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.