Servlets Page Redirection - Java Servlets

What is Servlets Page Redirection?

Page redirection is a procedure where the client is directed to a new location other than demanded. Page redirection is usually used when a document moves to a new location or may be since of load balancing.

The modest way of redirecting a request to alternative page is using method sendRedirect() of response object. Resulting is the signature of this method –

This technique sends back the reply to the browser along with the status code and new page location. You can also use setStatus() and setHeader() methods together to achieve the same –

Example

This instance demonstrations how a servlet performs page redirection to another location –

Now let us compile above servlet and create following entries in web.xml

Currently call this servlet using URL http://localhost:8080/PageRedirect. This would redirect you to URL http://www.photofuntoos.com.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java Servlets Topics