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¶2=value2 When a user types in the above URL in a ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Struts Question:Using session object to store info
http://www.mywebsite.com/process.jsp...1¶2=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! |
|
|||
|
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. |
|
|||
|
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? |
|
|||
|
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. |
![]() |
| Thread Tools | |
|
|
|
||||
| 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 |