JSP include file (variable) loading files dynamically

Source: Internet
Author: User

includeFile variables) Loading files dynamically



<% @include file= "/includes/<%=id%>/abc.html"%> This write system will be error, indicating that the file is not found, mainly because <%=id%> is not resolved to the ID you want.

OK, let's change the way, using <jsp:include page= "/includes/<%=id%>/adc.html" ></jsp:include> is not it possible. The colors shown in Eclipse <%=id%> tell us that this should be possible. But, I'm sorry, this is really not going to work.

So let's change our mind, we'll take the value behind the page as a variable and write it like this:

<%string add = "/includes/" + id+ "/abc.html"; %>
<jsp:include page= "<%=add%>" ></jsp:include>

It is possible to test this. In turn, you might think

<%string add = "/includes/" + id+ "/abc.html"; %>
<% @include file= "<%=add%>"%>



Whether or not, after testing, this is still not possible.



Turn from: http://hi.baidu.com/hankers/blog/item/dc1bda54489c215dd0090674.html

<%@ include file= ""%>
A static include file, that is, inserts the contained file at compile time. File cannot be a variable URL, nor can it take over any of the files specified by file, and the path referred to by file must be the path relative to the JSP Web page.
If you use <%@ include file= "common.jsp"%&gt in includebydirectives.jsp, the generated Includebydirectives_ Jsp.java will include the common.jsp file in the.
Note: In common.jsp, includebydirectives.jsp can reference mutually defined variables, methods. The directives defined in COMMON.JSP are merged into the includebydirectives.jsp.
<jsp:include page= ""/>
A dynamic include file, which is the result of running the include file at run time. Grammar:
<jsp:include page= "{urlspec | <%= expression%>}" flush= "true | False "/>
Or
<jsp:include page= "{urlspec | <%= expression%>}" flush= "true | False ">
<jsp:param name= "PN" value= "{PV | <%= expression%>}"/> *
</jsp:include>
If you use <jsp:include flush= "true" page= "common.jsp" ></jsp:include&gt in includebyaction.jsp; In the generated Includebyaction_jsp.java, a section is added to the include:
Org.apache.jasper.runtime.JspRuntimeLibrary.include (Request, Response, "common.jsp", out, true);
Note: includebyaction.jsp and common.jsp are independent of each other, includebyaction.jsp just add the results of common.jsp implementation.



For more detailed information, please refer to: http://hi.baidu.com/%D2%BB%C9%FA%CF%B7/blog/item/694657f378c5305c352accf2.html

JSP include file (variable) loading files dynamically

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.