Exforsys

Online Training

Struts Question:Using session object to store info

This is a discussion on Struts Question:Using session object to store info within the Java Tutorials forums, part of the Articles and Tutorials category; http://www.mywebsite.com/process.jsp...1&para2=value2 When a user types in the above URL in a ...


Go Back   Exforsys > Articles and Tutorials > Java Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-11-2004, 08:59 PM
akpraveen
Guest
 
Posts: n/a
Struts Question:Using session object to store info

http://www.mywebsite.com/process.jsp...1&para2=value2

When a user types in the above URL in a browser, I am trying to get para1 value and para2
value from the URL query string and store it in session.

Here is the method I tried!

In the reset() method of the ProcessForm class, I first got the values of para1 and para2
using
String Parm1 = session.getParameter(\"para1\");
String Parm2 = session.getParameter(\"para2\");

and then tried to write to the session using

request.getSession().setAttribute(\"Parm1\",Parm1);
request.getSession().setAttribute(\"Parm2\",Parm2);

So, all the above code is in the reset() method of the ProcessForm class.

When I go to the next page, say process2.jsp, and retrieve session information from
Process2Form\'s reset() method, I am getting \"null\" as the value for Parm1 and Parm2.

Am I doing something wrong or is there another way to do this?

Currently, in the ActionMappings, all Form beans have scope set to \"request\". I tried to change
this to \"session\", but to no use!

Any help would be appreciated!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-11-2004, 09:58 PM
Senior Member
 
Join Date: Nov 2004
Posts: 132
Vasu
Re:Struts Question:Using session object to store info

Praveen,

When you use request.getSession().setAttribute(\"Parm1\",Parm1);
it creates new session and sets the attribute.

So while retreiving session information from Process2Form\'s reset() method,
try like this:
request.getSession(false).getAttribute() instead of
request.getSession().getAttribute() , so that it will use the existing session.

If you didnot provide false parameter it will creates new session. So u r unable to find the data in the new session.

Hope this helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-11-2004, 10:59 PM
akpraveen
Guest
 
Posts: n/a
Re:Struts Question:Using session object to store info

Cool!

Another question.

There are three pages -

InitialPage.jsp
CollectInfo.jsp
FinalPage.jsp

If a user comes to FinalPage.jsp directly, he/she should be routed/redirected to InitialPage.jsp

How do I implement this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-11-2004, 11:46 PM
Senior Member
 
Join Date: Nov 2004
Posts: 132
Vasu
Re:Struts Question:Using session object to store info

You can use Request Dispatcher methods or jsp: forward or html meta tags.

In your third jsp page
<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=page1.jsp\">

When you redirect or submit to a page, that URLwill show up on the browser\'s address bar and history and will be what gets loaded when the browser\'s refresh or back buttons are used. When you forward to a page, it will show up neither in the address bar nor in the history, so the browser\'s refresh button would load the previous page.

For example, if 1.jsp does a jsp:forward to 2.jsp. If you type in \"1.jsp\" in the browser\'s address bar, you will see 1.jsp there, but the browser will display the results of 2.jsp.

If 1.jsp does a response.sendRedirect() to 2.jsp and you type in \"1.jsp\" in the address bar, you will see \"2.jsp\" in the address bar and the browser will display the results of 2.jsp.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Comp.software-eng FAQ (Part 0): periodic postings and archives David Alex Lamb Tech FAQ 4 11-06-2005 06:15 AM
Apple II Csa2 FAQs: 1Main-Start, Part 1/25 rubywand@swbell.net Tech FAQ 21 10-19-2005 01:39 AM
GemStone FAQ (v.1.0) Vikas Malik Tech FAQ 0 10-19-2005 01:38 AM
Comp.software-eng FAQ (Part 0): periodic postings and archives David Alex Lamb Tech FAQ 4 10-09-2005 06:15 AM
Comp.software-eng FAQ (Part 4): CASE tool vendors David Alex Lamb Tech FAQ 0 08-01-2004 06:15 AM


All times are GMT -4. The time now is 07:04 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.