This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes getNamedDispatcher confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "getNamedDispatcher confusion" Watch "getNamedDispatcher confusion" New topic
Author

getNamedDispatcher confusion

Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Dear All,

I am looking forward to know the following aspects related getNamedRequestDispatcher(String)

  • 1. Why request attributes for forwarding and request are not added into getNamedRequestDispatcher()
  • 2. What's the practical use of getNamedRequestDispatcher()


  • Any pointers would be useful.

    BR,


    Prithvi,
    My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Bartender

    Joined: Apr 07, 2010
    Posts: 1629
        
      23

    Hi Prithvi,

    Why request attributes for forwarding and request are not added into getNamedRequestDispatcher()

    The specifications give no explanation "why they should not be set", they only tell that they should not be set. The only logical explanation I can think of is that the getNamedRequestDispatcher() can be used to forward or include to Servlets that are configured in the web.xml without a <servlet-mapping>. It is actually the only way to reach a Servlet or JSP that cannot be reached directly by the client.

    Probably the guys who wrote the specs thought that you would be interested in the request attributes (like "javax.servlet.forward.request_uri") until you have reached the point of using Servlets that are "protected from the outside URLs". If you are still interested in these parameters then you can still add them as an attribute to the request yourself though....

    What's the practical use of getNamedRequestDispatcher()

    Getting to Servlets in your web-application that should not be reached directly from a client

    Regards,
    Frits
    Prithvi Sehgal
    Ranch Hand

    Joined: Oct 13, 2009
    Posts: 774
    Thanks Frits for the explanation.

    I am just wondering what is the practical use? Do we use getNamedDispatcher() pretty often?

    BR,
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Bartender

    Joined: Apr 07, 2010
    Posts: 1629
        
      23

    I am just wondering what is the practical use? Do we use getNamedDispatcher() pretty often?

    I haven't other than during my certification preparation... and nowadays with all the mvc-frameworks around we hardly configure Servlets other than the ControllerServlet in the web.xml. I doubt if those frameworks use the getNamedDispatcher() "under the hood" at all.

    Regards,
    Frits
    Prithvi Sehgal
    Ranch Hand

    Joined: Oct 13, 2009
    Posts: 774
    Dear Frits,

    Thanks for your explanation.

    BR,
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: getNamedDispatcher confusion
     
    Similar Threads
    How to persist form data across different pages
    Best way to make sortable columns?
    Caching Issue: How to force HTML/JSP to refresh?
    Request attributes
    how to show user objects in jsp page