java left logo
java middle logo
java right logo
 

Home arrow Java EE Tips arrow JavaServer Pages arrow How to include content from outside a JSP context
 
 
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: 4086
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 content from outside a JSP context E-mail
User Rating: / 20
PoorBest 

Sometimes, there is a need to include a JSP segment from outside the including file's context. Example below shows how to use c:import tag from JSTL tag-library which gives JSP page authors much flexibility in pulling in resources from inside and outside their web application. The c:import tag allows a page to import web resources from outside JSP's web container, from another context in the same web container and from the same context, similar to using jsp:include.

Here we include page-segment header.jsp from outside context /sample. The url attribute specifies the resource to include; the context attribute declares the context from which the JSP imports the resource:

<%@page contentType="text/html"%>

////////////// first: include a tag-library by inserting the taglib:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

////////////// using the c:import tag to import an external URL:

<html>

  <c:import url="/header.jsp" context="/sample" />

  <body>
    <h2><c:out value="${param.title}" /></h2>

    <jsp:useBean id="dateString" class="java.util.Date"/>
    The time is  <c:out value="${dateString}" />.
    <br /><br />
  </body>

  ....

</html>

The c:import tag inserts the text generated by /dbproj/header_tag.jsp in the part of the code where the c:import tag is located. The /dbproj context path represents a different web application or context than the importing JSP. The top of the importing page now looks like the following text, since this is the HTML that the imported file produces:

////////////// here is an included external segment:

  <head>
      <title><%= request.getParameter("title"%> </title>
  </head>


 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.