Exforsys
+ Reply to Thread
Results 1 to 4 of 4

Struts Question:Using session object to store info

This is a discussion on Struts Question:Using session object to store info within the Java forums, part of the Programming Talk category; http://www.mywebsite.com/process.jsp...p;para2=value2 When a user types in the above URL in a browser, I am trying to get para1 value and ...

  1. #1
    akpraveen Guest

    Struts Question:Using session object to store info

    http://www.mywebsite.com/process.jsp...p;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!


  2. #2
    Vasu is offline Member Array
    Join Date
    Nov 2004
    Answers
    36

    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.


  3. #3
    akpraveen Guest

    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?


  4. #4
    Vasu is offline Member Array
    Join Date
    Nov 2004
    Answers
    36

    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.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...