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. 




0 comments:

Post a Comment

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic