Example for sendRedirect (Both servlets are in same web application)

The sendRedirect method is used to send a temporary redirect response to the client with  specified redirect location URL.The client collect the destination URL and generates request to the destination program.


If the response has already been committed, this method throws an IllegalStateException .


Example for sendRedirect Syntax :

ServletResponseObject . sendRedirect(“<URL>“);


Example for sendRedirect Example for sendRedirect method :

In the below example , both calling servlet ( and called JSP (result.jsp)  are in the same web application.


create a servlet We can also call a servlet from sendRedirect method by using it’s URL .


Directory structure :
Use of ServletConfig object in servlet with an example


Example for sendRedirect index.jsp

Example for sendRedirect

In the above servlet ,The redirection  URL is


http : Hypertext transfer protocol.
localhost : Ip address ( also indicates the localhost).
8080 : Server port.
redirectionInsideWebApp : Web application name.
result.jsp : Called JSP file.
userName : Parameter name.
name : Parameter value.


Example for sendRedirect web.xml

Example for sendRedirect result.jsp


Example for sendRedirect Execution Result:

Enter the name and click Redirect button.
Example for sendRedirect

The response redirects to the specified URL from the browser window (Client).
Use of ServletConfig object in servlet with an example



Related Posts :
AES Password Encryption in javascript and decryption in java – servlet
Kill or invalidate session using session id ( concurrent login )
Servlet Filter ( Request and Response filters in servlets ) example
URL rewriting in servlets ( Servlet session tracking )
Servlet Cookies ( Servlets session tracking with cookie )
Hidden form field in servlets ( Servlet session tracking )
Request attributes in servlet with an example ( Attribute scope )
Session attributes in servlet with example (Attribute scope)
   [will not be published]

^ <