Tracking Session using URL rewriting


 

Tracking Session using URL rewriting

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

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");

0

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

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

</p>

1

<%}

else

{

2

String string = response.encodeURL(

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

%>

3

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

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

<% }%>

4

URLrewriting.jsp

<html>

<head>

5

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

</head>

<body><center>

6

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

</font>

</center>

7

</body>

</html>

OUTPUT :

8

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

9

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

Download Source Code

0

Ads