Results 1 to 3 of 3

Thread: Storing form variables in a session

  1. #1
    Contributing Member
    Join Date
    Feb 2007
    Answers
    47

    Storing form variables in a session

    Hi,

    I have a form with some variables...say.. i have employee,designation

    I will enter employee value on this page..and click on next that navigates to the next page..

    On the next page..if i click on back..whatevr i have entered for employee on the first page i need to retain...

    I can do this by using hidden variables..posting to the next page and getting it back when i click on back..

    But,i dont want that traffic to happen.

    As soon as i enter the values on the first page,i want to store all these and when the back is clicked i have to retain.

    Please let me know how i cn do this with session variables.

    As i m a fresher in jsp,servlets..concepts like session..i dnt hv any idea..plz explain me in detail.

    Thanks in advance
    Neelima


  2. #2
    Junior Member
    Join Date
    Sep 2007
    Answers
    8

    Smile Re: Storing form variables in a session

    Hi

    Are u using struts?

    If so, then whatever the data entered in that page is mapped to the instance variables in the ActionForm class.

    Then by using JSTL tags u can assign the values to the textbox by using the value attribute as shown below.

    <input name="abc" id="abc" type="text" tabindex="1" size="12" autocomplete="off" maxlength="9"
    value='<cut value="${Form.abc}"/>' />

    Form-> ActionForm class which u r using..

    Regards,

    Raghu


  3. #3

    Re: Storing form variables in a session

    hi ,

    we can retain the values using request and session.
    By request ,you need to pass the req object every page if u want to get back details by using hidden fields. before putting values into hidden u need to set values into request scope.
    request.setAttribute("reqvalue",fields);
    we need to pass this req scope in every page using hidden fields as <input type="hidden" name=field name" value="${reqvalue.fieldname}">

    by session,we dont need any hidden parameters for setting session in page. whereever u want session scope object by callng getAttribute is enough. following steps u need to follow :

    HttpSession session=request.getSession("true");
    session.setAttribute("sessionValues",fields);
    String fieldname= (String) session.getAttribute("sessionValues");

    Scope will be availble sequence of all pages where u are going to usee this session. and we can retrive back the details also.

    as per your application requirement, we can implement scopes.
    if u hav any Q ,reply me back


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact