aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Difference JSP File & JSP Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Difference JSP File & JSP Page" Watch "Difference JSP File & JSP Page" New topic
Author

Difference JSP File & JSP Page

rahul dighe
Ranch Hand

Joined: Apr 17, 2001
Posts: 44
HI,
with regard to issues related to using include directive vs standard action there is a statement
"The include directive interprets its file attribute relative to the current jsp file whereas <jsp:include> actions are interpreted relative to the current JSP Page"??
i can't seem to understand the difference in the terms how is the "file" different from the "page" ?? can anyone please try to explain


<BR>Rahul Dighe
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3285
    
    7
JSP file is the raw file, containing the JSP code. JSP page is the output of the servlet engine when it processes a JSP file at request time.
The difference is key in understanding include directive and include action. include directive is a compile time inclusion of the jsp file (raw content) into another jsp file, so the resulting servlet contains the code of both the jsp files. While include action is a request time inclusion of the output of a jsp file into the output of another jsp file i.e both JSP files are compiled into separate servlets and executed separately. Only their output is added.
HTH,
Paul.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Jignesh Malavia
Author
Ranch Hand

Joined: May 18, 2001
Posts: 81
Thanks Paul.
Originally posted by rahul dighe:
HI,
with regard to issues related to using include directive vs standard action there is a statement
"The include directive interprets its file attribute relative to the current jsp file whereas <jsp:include> actions are interpreted relative to the current JSP Page"??
i can't seem to understand the difference in the terms how is the "file" different from the "page" ?? can anyone please try to explain

Rahul,
The phrases "relative to the jsp file" and "relative to the jsp page", mean that when the container has to select an included component using a relative URL, it looks at the file's current physical location in case of the directive while it looks at the page's current URL in case of the action.
To make it clear, suppose we have the following four conditions
1) A directory structure like this
doc-root/dir1/
doc-root/dir1/a.jsp
doc-root/dir1/b.jsp
doc-root/dir2/
doc-root/dir2/b.jsp <--- note this
2) a.jsp includes b.jsp twice, once using the dirctive and once using the action as follows
<%@ include file='b.jsp'%>
<jsp:include page='b.jsp' />
Note that in both the cases, file and page, we are using non-root-relative URLs. That is, the URL of the included component is relative to the current JSP file and current JSP page respectively.
3) web.xml has a <servlet> entry with a <servlet-name> A and <jsp-file> /dir1/a.jsp
4) web.xml has two <servlet-mapping> entries
4a) <url-pattern> /dir1/a.jsp is mapped to <servlet-name> A
4b) <url-pattern> /dir2/a.jsp is mapped to <servlet-name> A
Note a.jsp does not exist in dir2. In 4b, /dir2/a.jsp is just a mapping.
We can access the same jsp page in two ways
First- using http://.../dir1/a.jsp
Second- using <a href="http://.../<b rel="nofollow">dir2</b>/a.jsp" target="_blank">http://.../dir2/a.jsp
Both the above will invoke the servlet named A, which is actually the same a.jsp page
In the first case,
a.jsp will include b.jsp from dir1 because of the include directive
a.jsp will include b.jsp from dir1 because of the include action
In the second case,
a.jsp will include b.jsp from dir1 because of the include directive
a.jsp will include b.jsp from dir2 because of include action
Reason - when we use http://.../dir2/a.jsp, the container searches for b.jsp using .../dir2/ as its base URL.
Hope that helps
Now to have more fun, try this
1. Create a file named c.jsp in dir2
2. Declare a servlet named C and point to file /dir2/c.jsp in web.xml
3. map servlet C to the url <a href="http://.../dir2/<b rel="nofollow">b</b>.jsp" target="_blank">http://.../dir2/b.jsp
4. Then access a.jsp using http://.../dir1/a.jsp
5. Then access a.jsp using http://.../dir2/a.jsp
And observe what you get in steps 4 and 5.
rahul dighe
Ranch Hand

Joined: Apr 17, 2001
Posts: 44
Thanks Jignesh,
i felt it would be something like this, although in none of the books i read was there any mention of mapping through web.xml , so the interpretation was not clear. even in the jsp specs they have given an example which doesn't desribe how the jsp pages are mapped in the web.xml ..
i will try out the example u have left for me to do, it would be quite instructive.
thanks again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference JSP File & JSP Page