Saurabh Gupta
Saurabh Gupta

Reputation: 449

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

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)


     **

Upvotes: 1

Views: 22802

Answers (3)

Niju
Niju

Reputation: 487

<input type="hidden" name="epnostorage" value="<%= request.setAttribute("epno", epno) %>" />
<input type="hidden" name="casestorage" value="<%= request.setAttribute("case", i) %>" />

What you have done here is wrong. If you need to set some values in hidden element it doesn't needs to set as request.setAtrribute() inside the element. You can set as

<%
  int someInteger = 0;
  String someString = "stringValue";
%>
<input type="hidden" name="someInteger" value="<%=someInteger%>" />
<input type="hidden" name="someString" value="<%= someString%>" />

After that you can get the values from hidden element where the action submit as

int someInteger = Integer.parseInt(request.getParameter("someInteger"));
String someString = request.getParameter("someString");

Upvotes: 0

Ganesh Rengarajan
Ganesh Rengarajan

Reputation: 2006

session is one way to store the value

session.setAttribute("name",value);

Upvotes: 1

Arthur Dent
Arthur Dent

Reputation: 795

The method ServletRequest.setAttribute(String, Object) is void (returns nothing), so there is no value to embed in the <%= ... %> tags you are using. I think you want getAttribute, or perhaps the more concise ${varname} syntax.

Upvotes: 0

Related Questions