• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Include directive Vs <jsp:include>

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The JSP 2.0 spec (Section - JSP.5.4) says


The page attribute of both the jsp:include and the jsp:forward actions are interpreted relative to the current JSP page, while the file attribute in an include
directive is interpreted relative to the current JSP file.



An example is also given:


Consider the following four situations built using four JSP files: A.jsp, C.jsp, dir/B.jsp and dir/C.jsp:
• A.jsp says <jsp:include page=”dir/B.jsp”/> and dir/B.jsp says <%@ include file=”C.jsp” %>. In this case the relative specification C.jsp resolves to dir/C.jsp.
• A.jsp says <%@ include file=”dir/B.jsp”%> and dir/B.jsp says <jsp:include page=”C.jsp”/>. In this case the relative specification C.jsp resolves to C.jsp.



I am confused how the container figures out which C.jsp to include in these cases. Basically, whats the difference between

current JSP page and current JSP file

? Can someone please clarify?

Thanks!!

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Please Delete. Made an unclear explanation]
 
Tresa P Anthony
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Am surprised at the lukewarm response.

Anyways, the quoted text (including the examples) in my original post is from the JSP 2.0 spec.
Please explain how the container figures out the correct resource to include.

Thanks!
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Tresa. Incase of <%@ include file=”dir/B.jsp”%> that is present in A.jsp, during translation phase(i.e, converting from .jsp to .java file) the JSP compiler goes to the 'dir' directive and finds the B.jsp, and place the file as it is in the A.jsp.(with <html><body>...</body></html>) Since B.jsp contains <jsp:include page=”C.jsp”/>, it will not be converted into .java file at this moment. Now the jsp compiler compiles A.java into .class file. Then it goes for execution, while executing, the container sees <jsp:include page="C.jsp" />(actually it is a dynmaic one), then the jsp compiler converts from .jsp to .java file, and then converts into .class file, and executes it, and the response object of it is added to the A.jsp's response object, and the response is sent to the client.

Incase of <jsp:include page=”dir/B.jsp”/> that is present in A.jsp, while the jsp compiler compiles A.jsp into A.java file, B.jsp's code will not be put into the A.java, it just addresses <jsp:include page="dir/B.jsp" />(since it is a dynamic one). During executing A.class, the container sees <jsp:include page="dir/B.jsp" />, then the job is handover to the jsp compiler,the jsp compiler goes to the 'dir' directory and sees the B.jsp's code and in the code it sees <%@ include file=”C.jsp” %>, since it is a static one, it addes the C.jsp's code(with <html><body>...</body></html>) and converts it into .java file, and compiles into .class file and starts executing, at last the response object is added to the A.jsp's response object and sent to the client.

The above process will varies from one implementor to the another.



Here the current JSP page and current JSP means, the the file or page that is under compiling or executing.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Include directive appends the content of a jsp file to other. If you use <%@ include file="B.jsp"> inside A.jsp, the content of B.jsp will be added to A.jsp where it was called. Then, the compiler will compile them together as A.jsp.

Include action is equivalent of RequestDispatcher.include(ServletRequest, ServletResponse). In where you use <jsp:include page="B.jsp"> inside A.jsp, the processing will be delegated to B.jsp.

Static include occurs during translation time, so, works with JSP files which are going to be compiled and executed together.
Dynamic include occurs at running time (at requesting), so, works with compiled JSP pages which process requests and responses separately.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic