• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Difference JSP File & JSP Page

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Enthuware Software Support
Posts: 4896
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic