java left logo
java middle logo
java right logo
 

Home arrow Java EE Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4098
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to include a file in a JSP page E-mail
User Rating: / 29
PoorBest 

This Java tips illustrates an example of a include a file in a JSP page. To include an HTML or JSP fragment in a JSP file, the include directive is used. The effect is essentially equivalent to replacing the directive with the contents of the included file.

The include file specified by include directive is always relative to the file containing the include directive. For example, if a file A.jsp includes dir/B.jsp which in turn includes C.jsp, C.jsp is assumed to be in the directory dir.

This example includes a file called relativeFragment.jsp which is located in the same directory as the current file:

    <%@ include file="relativeFragment.jsp" %>

This example includes a file called /absoluteFragment.jsp which is located relative to the web application's root:

    <%@ include file="/absoluteFragment.jsp" %>

At the time the main JSP page is accessed, the include directive permanently captures the current contents of an included file. Changes to the included file will not affect the results of the main JSP page. If the application depends on capturing the contents of the included file at the time of each request, then an include action should be used.

These examples demonstrate how to use an include action to dynamically include the contents of a relative or absolute fragment at every request:

    <jsp:include page="relativeDynFragment.jsp" />
    <jsp:include page="relativeDynFragment.html" />
    <jsp:include page="/absoluteDynFragment.jsp" />
    <jsp:include page="/absoluteDynFragment.html" />

It is also possible to dynamically choose the file to include. This example determines the file to include from a request parameter:

    <jsp:include page='<%= request.getParameter("incFile"%>' />

 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.