【问题标题】:how do i pass form data from one jsp page to another?如何将表单数据从一个 jsp 页面传递到另一个页面?
【发布时间】:2011-09-21 19:30:34
【问题描述】:

我需要将数据从 1.jsp 传输到 2.jsp

我需要将复选框和单选按钮以及下拉菜单从 1.jsp 传递到 2.jsp,然后在 2.jsp 中使用该数据生成正确的页面

有没有办法在不通过 url 传递该信息的情况下这样做?

这是我的表单:http://jsfiddle.net/S2SxN/10/

所以如果我有一个带有单选按钮 id="extra" 的表单,当我在 1.jsp 中将其提交到 2.jsp 时,我可以获得它的值,对吗?!?

1.jsp:

<form name="form1" id="form" action="/2.jsp">
    <table>
        <tr>
            <td>I am interested in:</td>
            <td><input type="radio" name="choice" value="consume" id="con"/> Cosuming and/or distributing OTC Markets data
            </td>
        </tr>
        <tr>
            <td></td>
            <td><input type="radio" name="choice" value="extranet" id="extra"/> Providing connectivity to OTC Markets(Extranet)</td>
        </tr>
        <tr>
            <td>
                <input type="reset" id="re">
                <input type="submit" id="sub" value="Submit">
            </td>
        </tr>
    </table>
</form>

2.jsp:

<% if(request.getParameter("extra") != null) { %>
    <h2>you selected <%= request.getParameter("extra") %></h2>
<% } else { %>
    <h2>you selected <%= request.getParameter("con") %></h2>
<% } %>

我得到“con”结果而不是“extra”的某种原因,当我得到“con”结果时它是空的...... 我做错了什么???

【问题讨论】:

  • 提交表单到 2.jsp 并让 Request.getParameter("") 成为你的朋友。
  • 这可能比您需要的要重,但您当然可以将其存储在数据库中。
  • 我认为@JHolyhead 是对的。是不是只是用 HTML 的方式来发送它为POST

标签: javascript forms jsp


【解决方案1】:

将表单作为帖子提交到 2.jsp,然后从帖子数据中取回值。或者这不是你的意思?

【讨论】:

  • 对不起,我已经投了反对票,因为像你这样的答案。没关系...
  • 所以我应该将 1.jsp 的动作设置为 2.jsp... 如
    然后使用 jquery 或 js 传递数据??
  • 将操作设置为 2.jsp 和发布方法。然后,您可以使用 Request.getParameter("formElementName") 检索所有表单值。 roseindia.net/jsp/UsingPostMethod.shtml有一个例子
  • 似乎对我不起作用=/我将操作设置为 2.jsp 并在 2.jsp 中我做 request.getParameter("extra") 来检查它是否为空,它只是添加了一些代码,您可以检查我是否正确执行了吗?
  • 在表单标签中添加method="post"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-17
  • 2015-04-04
  • 2016-12-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多