【问题标题】:how to pass data in an hidden field from one jsp page to another?如何将隐藏字段中的数据从一个jsp页面传递到另一个页面?
【发布时间】:2013-06-13 19:23:45
【问题描述】:

我在 jsp 页面的隐藏字段中有一些数据

<input type=hidden id="thisField" name="inputName">

如何在提交时访问或传递此字段到另一个页面?

【问题讨论】:

    标签: jsp hidden-field


    【解决方案1】:

    要传递值,您必须在 &lt;input&gt; 语句中包含隐藏值 value="hiddenValue",如下所示:

    <input type="hidden" id="thisField" name="inputName" value="hiddenValue">
    

    然后通过访问请求对象的参数,以与恢复可见输入字段的值相同的方式恢复隐藏的表单值。这是一个例子:

    此代码位于您要隐藏值的页面上。

    <form action="anotherPage.jsp" method="GET">
        <input type="hidden" id="thisField" name="inputName" value="hiddenValue">
    <input type="submit">   
    </form>
    

    然后在“anotherPage.jsp”页面上,通过调用隐式request 对象的getParameter(String name) 方法来恢复值,如下所示:

    <% String hidden = request.getParameter("inputName"); %>
    The Hidden Value is <%=hidden %>
    

    上述脚本的输出将是:

    The Hidden Value is hiddenValue 
    

    【讨论】:

      【解决方案2】:

      Alex 的代码效果很好。请注意,当您使用 request.getParameter 时,您必须使用请求调度程序

      //Pass results back to the client
      RequestDispatcher dispatcher =   getServletContext().getRequestDispatcher("TestPages/ServiceServlet.jsp");
      dispatcher.forward(request, response);
      

      【讨论】:

        猜你喜欢
        • 2010-11-30
        • 1970-01-01
        • 2012-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-04
        • 1970-01-01
        • 2014-04-17
        相关资源
        最近更新 更多