Hi everyone I am unable to understand the session management concept
I am providing the program and I will tell exactly where I am stuck
1> This is my login page named as form.html
<HTML>
<HEAD>
<TITLE> sending data to a server </TITLE>
</HEAD>
<BODY>
<p> enter the details</p> <br>
<form method="POST" action="submit_Data" >
Enter your Name here<input type='text' name='Name'><br> Enter your age here <input type='text' name='age'><br>
<input type='submit' value='submit'>
</form>
</BODY>
</HTML>
2> from here the request goes to a
Servlet below is the code
package myServlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class scwcd extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
PrintWriter out = res.getWriter();
String Name=req.getParameter("Name");
String age=req.getParameter("age");
HttpSession sn=req.getSession();//line 1
sn.setAttribute("name",Name);//line 2
sn.setAttribute("age",age);// line 3
RequestDispatcher
rd=req.getRequestDispatcher("/pages/test.jsp");//line 4
rd.forward(req,res);
}
}
3>In line 1 I am getting a new session and in line 2 and line 3 Iam setting
two attributes then in line 4 I am dispatching the request to a
jsp(test.jsp)
4>In test.jsp what basically I am doing is I am asking the client to enter another field the code is as below:-
5>now when the user press submit button the control goes to another Servlet
in the Servlet I am trying to retrieve the attributes set in the scwcd Servlet the code is mentioned below:-
as far as my understanding goes :-
when the client enters his name and age in the form.html the request
goes to scwcd servlet where we get a session object then the request
is dispatched to a second jsp asking him for plot no and when the user
enters the plot number the request goes to "testservlet" servlet where
I have written a line (req.getsession()) as my second request carries the
session id it is matched and the server comes to know that this another request from the same client and when I write get attribute it gives me back the set attributes and I display it uptill this it is ok but when I disable the cookies the server should generate a new session object and getAttributes should return null but in my case I am getting the set attributes. I am confused.either there is a flaw in my understanding
or somehow I am not disabling the cookies in my IE....,
Please help to let me know where I am wrong
Thanks in advance(for showing patience!!!)
-Abhisek