是否可以在JSP的页面指令中包含Expression标记? [英] Is it possible to include an Expression tag inside a page directive in JSP?

查看:64
本文介绍了是否可以在JSP的页面指令中包含Expression标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用通过另一个jsp传递给jsp的参数,将一个jsp文件包含到另一个文件中.

I am trying to include a jsp file into another one by using the parameters passed to the jsp through another jsp.

代码是

Template.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

    <% String t = (String) request.getParameter("title"); %>
    <title><%=t%></title>

    <link type="text/css" rel="stylesheet" href="css/jquery.dataTables.min.css">
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.dataTables.min.js"></script>
    <script type="text/javascript">

      <% String js = (String) request.getParameter("script"); %>
      <%@ include file="<%=js%>" %>

    </script>
  </head>
  <body>

    <% String table = (String) request.getParameter("table"); %>
    <%@ include file="<%=table%>" %>

  </body>
</html>

Table.jsp

 <table id="Profiletable" class="display" cellspacing="0" width="100%"> 
   <thead>
    <tr>
      <th>Name</th>
      <th>Profile</th>
    </tr>
   <thead>
 </table>

script.js

$(document).ready(function() {
    var table =   $('#Profiletable').DataTable( {
                    "ajax":"Profiles.txt",
                    "columns":    [
                         {"data" : "Name"},
                         {"data" : "Profile"}
                    ]
                  } );
});

includer.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<jsp:include page="template.jsp">
  <jsp:param name="title" value="Test"/>
  <jsp:param name="script" value="script.js"/>
  <jsp:param name="table" value="table.jsp"/>
<jsp:include/>

但是上面的代码不起作用.如果我硬编码在的值 <%@ include file="fileName" %> 然后就可以了.

But the above code is not working. If i hard code the values at <%@ include file="fileName" %> then it works.

推荐答案

JSP include指令和JSP include操作之间的区别

JSP包含指令

<%@ include file="filename" %> 

  • 在JSP页面翻译时间中,include指令中给出的文件内容按原样被粘贴放置在JSP include指令所在的位置用来.然后将源JSP页面转换为Java servlet类.包含的文件可以是静态资源或JSP页面.通常,JSP include指令用于包含标头横幅和页脚.

    • At JSP page translation time, the content of the file given in the include directive is pasted as it is, in the place where the JSP include directive is used. Then the source JSP page is converted into a java servlet class. The included file can be a static resource or a JSP page. Generally JSP include directive is used to include header banners and footers.

      JSP编译过程是,仅当源JSP页面已更改时才对其进行编译.如果所包含的JSP文件发生更改,则将不会编译源JSP文件,因此修改不会反映在输出中.

      The JSP compilation procedure is that, the source JSP page gets compiled only if that page has changed. If there is a change in the included JSP file, the source JSP file will not be compiled and therefore the modification will not get reflected in the output.

      <jsp:include page="relativeURL"/> 
      

      • jsp:include动作元素就像一个函数调用.在运行时,所包含的文件将被执行,结果内容将包含在源JSP页面中.调用包含的JSP页面时,请求和响应对象都将作为参数传递.

        • The jsp:include action element is like a function call. At runtime, the included file will be executed and the result content will be included with the source JSP page. When the included JSP page is called, both the request and response objects are passed as parameters.

          如果需要传递其他参数,则可以使用 jsp:param 元素.如果资源是静态的,则由于不需要处理,因此其内容将插入到调用的JSP文件中.

          If there is a need to pass additional parameters, then jsp:param element can be used. If the resource is static, its content is inserted into the calling JSP file, since there is no processing needed.

          使用include指令是不可能的.在构建JSP的Servlet的时间比执行页面上的Java代码早得多的时候,该指令会得到评估.

          This is not possible with the include directive. The directive gets evaluated when the servlet for the JSP is being constructed long before the Java code on the page gets executed.

          您可以使用带有<jsp:include/>标记的变量路径,该变量路径将在运行时进行评估.

          You can use a variable path with the <jsp:include/> tag, which gets evaluated at run time.

          这篇关于是否可以在JSP的页面指令中包含Expression标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆