| Author |
Help Needed Regarding Session Management
|
Dash Abhisek
Ranch Hand
Joined: Jul 20, 2008
Posts: 63
|
|
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
|
 |
Ranil Liyana Arachchige
Ranch Hand
Joined: Sep 20, 2008
Posts: 71
|
|
Abhisek, did you clear the page cache in the browser during the second scenario? if not try clearing the browser cache,and also if you disable the cookie on the browser , unless there is explicit URL rewriting there is no way the you can join a session. please try the browser cache clearing first! Rani LiyanaArachchi SCJP 1.4(80%) , SCWCD5.0 (91%)
|
SCJP 1.4 (80%) , SCWCD5.0 (91%) , SCEA / OCMEA
|
 |
Dash Abhisek
Ranch Hand
Joined: Jul 20, 2008
Posts: 63
|
|
Hi Ranil, Lots of Thanks for the help but still I am facing the problem I am expecting values as null but somehow I am getting the values...,just wanted to know two things from you:- 1>am I right with the concept? 2>can you give the location where from I can clear the cache you talked about actually I tried and I went to tools->internet options->content(tab)->clear
"ssl"
state where it asks me to confirm if I want cache to be cleared or not. also after I did this I tried to log in into my yahoo account which didn't allow me saying cookies are disabled.. Thanks Abhisek
|
 |
Ranil Liyana Arachchige
Ranch Hand
Joined: Sep 20, 2008
Posts: 71
|
|
Hi Abhisek, To clear browser cache in IE 7 you would have to go , tools -> internet options ->general (tab) --> and clear the browsing history the logic is ok, it has no flaws , it looks like once you have dissabled cookies you must be still using the same browser window, and though you dissabled cookies it would not be effective on the current session just after the cookie dissabling action. I suggest you to fire up a new browser window and do the same under cookie dissabled scenario. It should work fine! hope this would solve your problem, regards.
|
 |
Dash Abhisek
Ranch Hand
Joined: Jul 20, 2008
Posts: 63
|
|
|
Thanks a lot it is now working.
|
 |
Ranil Liyana Arachchige
Ranch Hand
Joined: Sep 20, 2008
Posts: 71
|
|
|
no problem, you are welcome
|
 |
 |
|
|
subject: Help Needed Regarding Session Management
|
|
|