• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javax.servlet.forward AND javax.servlet.include

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this for all the values

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


 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic