how to store the values of request parameter in jsp for next page

22,179

session is one way to store the value

session.setAttribute("name",value);
Share:
22,179
Saurabh Gupta
Author by

Saurabh Gupta

Apparently, this user prefers to keep an air of mystery about them.

Updated on June 23, 2020

Comments

  • Saurabh Gupta
    Saurabh Gupta about 4 years

    i have read in this forum itself when we use request.setAttribute and request.getAttribute

    its value is only retained untill the jsp page is loaded. so they suggestted to use a hidden form and when i am ussing that hidden form - i cannot seem to get it right. it says that it is not permitted for void values of which i make sure that all the values being stored through .setAttribute have some initialized values.

    here is the code where error showed

         **org.apache.jasper.JasperException: Unable to compile class for JSP: 
    
         An error occurred at line: 83 in the jsp file: /season1.jsp
         The method print(boolean) in the type JspWriter is not applicable for the arguments (void)
         80:   <!-- end .content --></div>
         81:   </form>
         82:   <%i=1;%>
         83:   <input type="hidden" name="epnostorage" value="<%= request.setAttribute("epno", epno) %>" />
         84:   <input type="hidden" name="casestorage" value="<%= request.setAttribute("case", i) %>" />
         85:   <%
         86:   }
    
    
         An error occurred at line: 84 in the jsp file: /season1.jsp
         The method print(boolean) in the type JspWriter is not applicable for the arguments (void)
         81:   </form>
         82:   <%i=1;%>
         83:   <input type="hidden" name="epnostorage" value="<%= request.setAttribute("epno", epno) %>" />
         84:   <input type="hidden" name="casestorage" value="<%= request.setAttribute("case", i) %>" />
         85:   <%
         86:   }
         87: else if(i==1)
    
    
         **
    
  • Saurabh Gupta
    Saurabh Gupta about 11 years
    i want to set the value for next jsp page to use .. this is the portion where i want to store the value for the next page to use..
  • Saurabh Gupta
    Saurabh Gupta about 11 years
    somebody suggested me that if i want to use the values for one page hidder form was better choice .. though i am trying to make a dynamic page here which has to use a value of variable again on the page so can u suggest me how that could be done..
  • Saurabh Gupta
    Saurabh Gupta about 11 years
    also if u use session to set attribute will it be forwarded to all the pages where i add session
  • Saurabh Gupta
    Saurabh Gupta about 11 years
    untill this error is removed and i cannot test the actual working as i cannot compile the code..
  • Ganesh Rengarajan
    Ganesh Rengarajan about 11 years
    it will forwarded all pages but if u want remove the session use removeAttribute to remove the session value
  • Arthur Dent
    Arthur Dent about 11 years
    Indeed the session is one way to get that done. The important considerations are that you delete it after use and that you scope your names to avoid collisions with other classes and pages using the same trick. For inspiration: static.springsource.org/spring/docs/3.1.x/javadoc-api/org/…
  • Saurabh Gupta
    Saurabh Gupta about 11 years
    ok thanks for the info but if i remove the session attribute on the same page will it be not loaded of .. how do u suggest of the location of using removeAttribute in a website
  • Saurabh Gupta
    Saurabh Gupta about 11 years
    also how do i get the attribute i set in session
  • Ganesh Rengarajan
    Ganesh Rengarajan about 11 years
    session.getAttribute("sessionname");
  • Saurabh Gupta
    Saurabh Gupta about 11 years
    i dont know , i dont know how it works and i cant find a working example of flash map.. so i will try the session one ..
  • Saurabh Gupta
    Saurabh Gupta about 11 years
    Duplicate local variable session - it gives theis error when i declare session variable with Httpsession session; and i have not declared the variable two times ..
  • Ganesh Rengarajan
    Ganesh Rengarajan about 11 years
    are you declared in your jsp,In jsp session is a inbuilt one so dont use httpsession ,directly specify the session.setAttribute("","");