• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with session

 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jsp called register.jsp. After verifying the user name and password in register.jsp it gets forwarded to thankyou.jsp if the verification is successful, if it failed it gets forwarded to register.jsp.
Here I am posting the reset method from the class that extends ActionForm.
---------------------------------------------
public void reset(ActionMapping mapping, HttpServletRequest request) {

HttpSession usersession = request.getSession(false);
String name=(String)usersession.getAttribute("username");
if (request.getParameter("userid")!=null | name == null){
System.out.println("THE USERID ATTRIBUTE COMING FROM REQUEST TO RESET IS " +request.getParameter("userid"));
usersession.setAttribute("username", request.getParameter("userid"));
//name=(String)usersession.getAttribute("username");
System.out.println("setting username attribute to "+(String)usersession.getAttribute("username"));
}
name=(String)usersession.getAttribute("username");
System.out.println(">>>>username attribute is " +name);
userid = name;

password = "";

}

---------------------------------------------
I have some problem with reset method or with session tracking. It happens when I test the application in the following order.

1.Open a browser window say window1 (IE)
2.Open a browser window say window2 (IE)
3.Enter username1 in window1 and click submit button
4.Enter username2 in window2 and click submit button
Now in window1, username field is pre filled with username1 and in window2 username field is pre filled with username2.
5.Now come to back to widow1 and place the cursor at the end of address line and hit enter in the key board. Now in window1, the username field is pre filled with username2. What I wanted was, pre fill each session with each user�s username. Can somebody suggest some thing? Any help appreciated.
[ June 01, 2006: Message edited by: PradeepPillai Pradeep ]
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you opening the second window? If you are hitting ctrl-n or File->New Window, the jsessionid cookie is passed to the new window. If you double click the icon for IE for each window, you probably won't get those results.

What are you trying to accomplish by this?
 
PradeepPillai Pradeep
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am opening a new window each time (double click on ie each time)
 
PradeepPillai Pradeep
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What am I trying to accomplish by this?

I am just trying to make sure that the appropriate user name has been reset in each session.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your App Server does session management using cookies as most do, you won't be able to test multiple sessions using the same computer. No matter how you open a new window in IE, it still gets it's cookies from the same place, and therefore will be assigned the same HttpSession by your App server.

If you don't have two different computers to test with, you might get away with using Firefox for one session and IE for another. I believe they each handle cookies differently and won't be assigned the same session by your App Server.

Just a note about style: The ActionForm is intended to be a simple JavaBean and its reset() method is designed to do any needed initialization before Struts populates its properties. In a Struts application, you would normally want to use the execute method of the Action class to do the types of things you're doing in your reset method.
[ June 02, 2006: Message edited by: Merrill Higginson ]
 
PradeepPillai Pradeep
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for your expert opinion. I tested in firefox and it works fine (I don�t use cookies). It works even if I test it in two firefox browsers. This issue has to do something with IE implementation.
My intension is to reset the user with his user name if the login fails or if he/she comes back to the login page or if he/she just goes to login.jsp again. Can I use execute method to do this? I value your opinion.
Thank you very much.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can accomplish this in the execute() method of the Action class. Remember, Struts populates the ActionForm for you as long as you've named your bean properties the same as the property name used in the <html:text> tag. You don't have to do anything to populate the properties.

In the execute method, just cast the ActionForm parameter as your subclass of ActionForm and then read its properties to get the user name and password. Once you have done this, you can add or remove them from the session object as you desire.
 
PradeepPillai Pradeep
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it populate the user name field when the user come back to the login.jsp page? Or when the user type in login.jsp in the browser?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the flow of events:

  • The user enters a name in the login form and presses the submit button
  • A request is sent to the App Server and intercepted by the Struts Action servlet
  • Action servlet delegates most of the work to RequestProcessor.
  • RequestProcessor checks the scope of your ActionForm bean. If it's scope is session, it retrieves it from the session. If it's scope is request, it instantiates a new ActionForm and puts it in the request scope
  • RequestProcessor calls reset() on your ActionForm
  • RequestProcessor populates the properties in the ActionForm bean using the setter methods you've provided. In your example, the RequestProcessor reads the "name" parameter from the request and calls setName() on your ActionForm.
  • Request processor finds your Action class, instantiates it, and calls its execute() method, passing the ActionForm as a parameter. At this point you can access the user name by casting the ActionForm you got as a parameter to your specific ActionForm, and then calling getName() on it.


  • The above description is simplistic and omits some important details, but I hope it gives you a general concept of how things work.
    [ June 03, 2006: Message edited by: Merrill Higginson ]
     
    reply
      Bookmark Topic Watch Topic
    • New Topic