This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.servlet.forward AND javax.servlet.include

 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check this for all the values

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


 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2270
76
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic