【问题标题】:how to store the values of request parameter in jsp for next page如何将请求参数的值存储在jsp中以供下一页
【发布时间】:2013-06-22 05:00:44
【问题描述】:

当我们使用时,我已经阅读了这个论坛本身 request.setAttribute 和 request.getAttribute

它的值只保留到加载 jsp 页面。 所以他们建议使用隐藏形式,当我使用该隐藏形式时 - 我似乎无法正确处理。它说不允许 void 值,我确保通过 .setAttribute 存储的所有值都有一些初始化值。

这是显示错误的代码

     **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)


     **

【问题讨论】:

    标签: jsp setattribute getattribute


    【解决方案1】:

    会话是存储值的一种方式

    session.setAttribute("name",value);
    

    【讨论】:

    • 有人建议我,如果我想使用一页隐藏表单的值是更好的选择.. 虽然我试图在这里创建一个动态页面,但它必须再次使用变量值页面所以你能建议我如何做到这一点..
    • 如果你使用 session 来设置属性,它会被转发到我添加 session 的所有页面
    • 直到这个错误被删除并且我无法测试实际工作,因为我无法编译代码..
    • 它将转发所有页面,但如果您想删除会话,请使用 removeAttribute 删除会话值
    • 好的,谢谢你的信息,但是如果我删除同一页面上的会话属性,它将不会被加载..你如何建议在网站中使用 removeAttribute 的位置
    【解决方案2】:

    方法ServletRequest.setAttribute(String, Object)void(不返回任何内容),因此您正在使用的&lt;%= ... %&gt; 标记中没有嵌入任何值。我想你想要getAttribute,或者更简洁的${varname} 语法。

    【讨论】:

    • 我想设置下一个jsp页面使用的值..这是我想存储下一个页面使用的值的部分..
    • 确实,会话是完成此任务的一种方式。重要的考虑因素是在使用后将其删除,并确定名称的范围以避免与使用相同技巧的其他类和页面发生冲突。寻求灵感:static.springsource.org/spring/docs/3.1.x/javadoc-api/org/…
    • 我不知道,我不知道它是如何工作的,我找不到 Flash 地图的工作示例。所以我将尝试第一个会话 ..
    【解决方案3】:
    <input type="hidden" name="epnostorage" value="<%= request.setAttribute("epno", epno) %>" />
    <input type="hidden" name="casestorage" value="<%= request.setAttribute("case", i) %>" />
    

    你在这里做错了。如果您需要在隐藏元素中设置一些值,则不需要在元素内设置为 request.setAtrribute() 。 可以设置为

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

    之后,您可以从操作提交的隐藏元素中获取值

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多