What are the different ways for browser redirection in JSP?

Answered

What are the different ways for browser redirection in JSP?

Ninja Asked on 18th September 2018 in Jsp.
Add Comment
1 Answer(s)
Best answer

There are two ways for browser redirection in JSP:

  1. Using response.sendRedirect()
  2. Using <jsp:forward /> element

A redirect is a totally different from a forward. The response.sendRedirect() creates a new request object which doesn’t carry any of old requests. The request handling JSP page tells the browser to make a new request to the target servlet or JSP page. The URL shown in the browser therefore changes to the URL of the new page when you redirect.

The <jsp:forward /> standard action is actually a call to HttpServletRequest.forward(String url) which passes the request object within the server to either a servlet or a JSP page. The new servlet or JSP page continues to process the same request and the browser is not aware of the fact that more than one servlet or page is involved. In other words, the client is not aware that the request is being forwarded anywhere. The URL shown in the browser stays unchanged when you do forward.

Ninja Answered on 18th September 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.