*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes javax.servlet.forward AND javax.servlet.include 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 "javax.servlet.forward AND javax.servlet.include" Watch "javax.servlet.forward AND javax.servlet.include" New topic
Author

javax.servlet.forward AND javax.servlet.include

Manikandan Jayaraman
Ranch Hand

Joined: Sep 15, 2004
Posts: 230
The forwarded-to servlet and the included servlet has access to 5 request attributes each.

javax.servlet.forward.request_uri
javax.servlet.forward.context_path
javax.servlet.forward.servlet_path
javax.servlet.forward.path_info
javax.servlet.forward.query_string

AND

javax.servlet.include.request_uri
javax.servlet.include.context_path
javax.servlet.include.servlet_path
javax.servlet.include.path_info
javax.servlet.include.query_string

Can I have an example with values for all these request attributes? Thanks in advance.


Regards,<br />Mani<br />SCJP 1.4 (95%)<br />SCWCD 1.4 (94%)
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
Can I have an example with values for all these request attributes? Thanks in advance.

In the destination servlet, just make a meryod call -

request.getAttribute(".............");
you can replace the dots by any of the attributes above.
the only condition is, the disptcher with which you forward the request,
must be obtained as -

request.getRequestDispatcher( ) or
getServletContext().getRequestDispatcher( )

the above attributes are not set if you use the getNamedDispatcher( ).

htht


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Manikandan Jayaraman
Ranch Hand

Joined: Sep 15, 2004
Posts: 230
Hi All,

My example's output alone for your quick reference!

What was done?
Forwarder.jsp simply forwards the request to Forwarded.jsp.
Forwarded.jsp also includes response from Included.jsp
All 3 JSPs in the same folder.

My request url
http://localhost:9090/mani-examples/jsp/Forwarder.jsp?name="Mani"

Output of Forwarded.jsp

javax.servlet.forward.request_uri = /mani-examples/jsp/Forwarder.jsp
javax.servlet.forward.servlet_path = /jsp/Forwarder.jsp
javax.servlet.forward.context_path = /mani-examples
javax.servlet.forward.path_info = null
javax.servlet.forward.query_string = name="Mani"

Output of Included.jsp
javax.servlet.include.request_uri = /mani-examples/jsp/Included.jsp
javax.servlet.include.servlet_path = /jsp/Included.jsp
javax.servlet.include.context_path = /mani-examples
javax.servlet.include.path_info = null
javax.servlet.include.query_string = null


Things to Note

1. Query String parameter reflects the query string of the forwarding page.
2. Where as, request_uri, servlet_path, context_path reflect the information of the forwarded page.


Can someone explain the path_info ?
Manikandan Jayaraman
Ranch Hand

Joined: Sep 15, 2004
Posts: 230
Can anyone explain me, what will be contained in path_info. I understood all the other attributes.

How to demonstrate path_info attribute?
varigireddy reddy
Greenhorn

Joined: Jun 25, 2010
Posts: 2
check this for all the values

http://myj2eelearnings.blogspot.com/2010/06/javaxservletforward-and.html


Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1634
    
  23

Hi Manikandan,

Query String parameter reflects the query string of the forwarding page.

Not exactly: all the attributes reflect information of the forwarding page.

With the include attributes it is the other way around: they reflect information about the included page instead of the including page.

Regards,
Frits
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.servlet.forward AND javax.servlet.include
 
Similar Threads
calling one servlet from another servlet
barcode display in JSP
j2eecertificate.com question
where are the request parameters declare
get servlet name from ServletRequestAttribute Listener