We can get RequestDispatcher object with HttpServletRequest object by calling getRequestDispatcher(String url) and passing the url as a String paramter but its not mandatory to start with " / " as it was in case of ServletContext . In this case path is taken as relative to the request. Container id responsible to dispatch the control from one servlet/jsp to another jsp/servlet.

How container is getting the path internally ?
Internally container is getting the whole path from the request object and completes the request URI by getting and appending the url from the getRequestDispatcher(String url).

Two important points :

1. If we are writing "/ " before the url then container consider the path relative to the context and
2. If we are not writing " / " before the url then container consider the path relative to the request  and hence no chance of getting any exception in either case.

Summary: So if we are getting the RequestDispatcher object with Request object then its not mandatory to write " / " before the url .If we are writing then container take it as relative to the context and if not then taking relative to the request. 




Related Posts:

  • forward() in servlet forward() is a method in RequestDispatcher interface which is used to dispatch the control from a servlet to another servlet/jsp. Container is responsible to dispatch the the control by finding the full path internally eith… Read More
  • Handling Session in Servlet Handling session defines how session should be managed internally. Session is meant for keeping track of user's information which is required further for the next proceeding requests. Scope of a session is alive from its cr… Read More
  • URL Re-writing in Session Handling URL Re-writing is a technique by which session data can be handled within the server side only.Client is not responsible for keeping any information regarding session. In this process at every request the required session da… Read More
  • include() in servlet include() is a method defined in the RequestDispatcher interface with ServletRequest and ServletResponse as a parameter. It is same as forward with slight difference of storing the content of both source and target resourc… Read More
  • Hidden Form field in Session handling One of the major disadvantage with the URL Rewriting is that passing session data with the URL makes visible to every one who are requesting for the resource. To over come this problem the concept of hidden form field is i… Read More

0 comments:

Post a Comment

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

201976

Online Members

Live Traffic