Home Tutorial Java Jsp Tracking Session using URL rewriting

 
 

Share on Google+Share on Google+
Tracking Session using URL rewriting
Posted on: June 30, 2010 at 12:00 AM
Advertisement
In this section we will discuss about tracking user's session using URL rewriting using a simple example.

Tracking Session using URL rewriting

In this section we will discuss about tracking user's session using URL rewriting using a simple example.

For tracking sessions, we can use URL rewriting in place of cookies. Since http protocol is a stateless protocol (as it is not persistent), whenever browser sends request then it is always interpreted as a new request. When the first request goes to the server, a session object is created .To maintain the session, server creates a token .The token is transmitted to the client by the response object and gets stored on the client machine. URL rewriting can also be used where the cookies are disabled by the user.

EXAMPLE :

URLrewriting.html

<html>

<head>

<title>How to use URL rewriting in jsp</title>

</head>

<body>

<center><B><font size="4" color="red">LOGIN PAGE</font></B>

<form method = "post" action = "URLrewritingMain.jsp">

<font size = 4 color="blue">Enter your name :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type = "text" name = "name"></font><br><br>

<font size = 4 color="blue">Enter your password :

<input type="password" name = "pwd" ></font><br><br>

<input type = "submit" name = "submit" value = "submit" >

</form>

</center>

</body>

</html>

URLrewritingMain.jsp

<%@ page session ="true" %>

<%

String name = request.getParameter("name");

String password = request.getParameter("pwd");

if(name.equals("ankit") && password.equals("abcde"))

{

session.setAttribute("username",name);

String string = response.encodeURL(

"URLrewritingSuccess.jsp?name=+name+&password=+password");

%> <p><font size = 4>Login successful</font>

<font size = 4><a href ='<%= string %>'>Please click here to go forward</a></font>

</p>

<%}

else

{

String string = response.encodeURL(

"URLrewriting.html?name=+name+&password=+password");

%>

<p><font size = 4>UserName /Password is Incorrect : </font>

<font size = 4><a href ='<%= string %>'>Click here to go back</a></font></p>

<% }%>

URLrewriting.jsp

<html>

<head>

<title>Welcome in In the program of URL rewriting</title>

</head>

<body><center>

<font  size = 6  color = "red" > Hello  < % =  session.getAttribute ( "username") %>

</font>

</center>

</body>

</html>

OUTPUT :

After Submitting Output will be........

IIf Login is Incorrect, the output will be......

Download Source Code

Advertisement

Related Tags for Tracking Session using URL rewriting:


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.

Posted on: June 30, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com