J2EE: Dynamic introduction of other files using the include tag in JSP

Source: Internet
Author: User

Recently, I 've been idle about building a development framework. I 've encountered many problems. Google is often disconnected from the Internet, so I have no choice but to build a VPN. I still like to use Google to search for technical issues. Another redz. com search engine is also very useful, and few garbage sites are found. All are digress.

For applications using frameworks, almost every page must contain some JS scripts and CSS style sheets that are required and used by the framework, in this way, I want to create a JSP page to output the HTML code that references common JS scripts and CSS style sheets. Then, you need to reference the General JS script and the JSP page of the CSS style sheet through the include tag. This ensures the uniformity of the Framework scripts and CSS style sheets referenced on all pages. To change the framework, you only need to modify this JSP file. Of course, the best way is to use custom tags to output HTML code such as JS scripts, this helps front-end developers and server developers to better handle their own work independently.

When I tried to use the include label due to path problems, the resource could not be found. At first, I thought it could not be used for output.

<JSP: Include page = "<% = PATH %>/JSP/commoncssandjs. jsp" Flush = "true"/>

After this label is used, the console displays an error message. Refresh multiple times. Sometimes the error is: attribute for %> "is not properly terminated
, Sometimes the error is: file & quot;/apps/DMS/jiaoyanke/& lt; % = PATH % & gt;/JSP/commoncssandjs. jsp & quot; not found

Later, I checked the dynamic include related articles and added my own attempts, which are summarized as follows:

1. The page attribute value of a tag can be a relative path URL or <% = expression %>, but only one of them can exist at the same time. Reference:. http://java.sun.com/products/jsp/tags/11/syntaxref1112.html

2. When the page property value is relative URL, for example:

For example, in tester. jsp

The relative path of tester is/apps/JSP/tester. JSP. then, if tester. the page attribute of the include tag in JSP is "/app2/beincluded. JSP. JSP.
When the page attribute is "app2/beshortded. jsp", the file/apps/JSP/app2/beshortded. jsp is referenced.

3. When the page property value is <% = expression %>, the path rules are the same as those above, but note that:

"<% = PATH %>", "<% = PATH %> /***. JSP "this is not acceptable, and even a space between the quotation mark and <% = %> cannot exist, that is," <% = PATH %>"
No. If there is a space between double quotation marks and <% = PATH %>, <% = PATH %> is interpreted as a string. The console will prompt that the file with the path "<% = PATH %>" cannot be found.

Related Article

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.