Share on Google+Share on Google+

Session Using URLRewriting

URLRewriting can be used in place where we don't want to use cookies.

Session Using URLRewriting


URLRewriting can be used in place where we don't want to use cookies. It is used to maintain the session. Whenever the browser sends a request then it is always interpreted as a new request because http protocol is a stateless protocol as it is not persistent. Whenever we want that out request object to stay alive till we decide to end the request object then, there we use the concept of session tracking. In session tracking firstly a session object is created when the first request goes to the server. Then server creates a token which will be used to maintain the session. The token is transmitted to the client by the response object and gets stored on the client machine. By default the server creates a cookie and the cookie get stored on the client machine.

URLRewriting can be used where we the cookies are disabled. Its a good practice to use URL Rewriting. In URLRewriting a string is appended

Code of the program is given below:

		<title>How to use encodeURL in jsp</title>
		<form method = "post" action = "EncodeURLProgram.jsp">
		<font size = 6>Enter your name  : 
<input type = "text" name = "name"></font><br><br>
		<font size = 6>Enter your password  :
<input type="password" name = "pwd" ></font><br><br>
		<input type = "submit" name = "submit" value = "submit" >


<%@ page session ="true" %>
    String name = request.getParameter("name");
	String password = request.getParameter("pwd");
	if(name.equals("Williams") && password.equals("abcde"))
		String string = response.encode
		<font size = 6><p>Please click here to go forward : </p></font>
		<font size = 8><a href ='<%= string %>'>WelcomeEncodeURL.jsp</a></font>
		String string = response.encode
		<font size = 6><p>You have entered a wrong 
value  : Click here to go back : </p></font>
		<font size = 6><a href ='<%= string %>'>encodeURL.jsp</a></font>
	<% }


		<title>Welcome in In the program of URL rewriting</title>
<font size = 6>Hello</font> <%= session.getAttribute("username") %>

The output of the program is given below:

When the value are correct:

On clicking the WelcomeEncodeURL.jsp the result will be.

If the value is incorrect:

The output will be again the encodeURL.jsp

Download this example.



Posted on: February 9, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Session Using URLRewriting  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
July 29, 2013

I can keep the session alive in multiple tabs Without kill the sessions on all the tabs. onthat time i copied the corresponding URL and paste in New tab it will go to that page , it will not Redirect to Home Page.