can we use sendRedirect() of HttpServletResponse to redirect to servlet or it is for only to redirect to html or jsp files what is defference between RequestDispatcher() of ServletRequest RequestDispatcher() of ServletContext
sendRedirect() means to tell the browser with status code that it needs to request again for another servlet or jsp resource. Browser history is also maintained in this case because browser will automatically hit a new request here and you know that because the URL @ address bar is changed.
In other words, suppose you have one resource on server named a.jsp, but at some point of time, a.jsp is made obsolete or no longer available on the server. But to let not user request go for 404 (page not found) you may follow send redirect assisting the browser to hit for another page named a1.jsp or any servlet in place of a.jsp because as said its no longer available.
Joined: Feb 28, 2007
what is defference between RequestDispatcher() of ServletRequest RequestDispatcher() of ServletContext
can we use sendRedirect() of HttpServletResponse to redirect to servlet or it is for only to redirect to html or jsp files.
It can be used to redirect to any resource that is defined in the WEB.xml. a) When you specify a JSP , web container will directly get that resource. b) If you specify a URL pattern then web container will use web.xml to decode the url pattern to a servlet or a JSP file [In case there is a servlet mapping with jsp-file]. Try these out , they are quite interesting.
Have a look at ServletContext.getNamedDispatcher() as well