【问题标题】:Transfer variable value from 1 jsp page to another jsp age将变量值从 1 个 jsp 页面转移到另一个 jsp 时代
【发布时间】:2018-07-04 12:43:22
【问题描述】:

我正在使用 MYSQL 数据库,而我正在使用 JSP 进行编程。现在我正在使用以下代码从我的 result.jsp 页面中的数据库中提取一个值:

String pid="";
while(resultSet.next()
{
<form action="report.jsp">
<%=resultSet.getString("patient_id") %>
<% pid=resultSet.getString("patient_id"); %>
<% request.setAttribute("acId", "pid"); %> 
<input type="submit"></input>
</form>
}

pid是用于存储Patient ID值的变量。

我想将该值转移到另一个 jsp 页面,即 report.jsp

我正在检索 repost.jsp 中的值,如下所示:

<%
String paid = (String)(request.getAttribute("acId"));
%>

然后我必须将此值存储在数据库中。但是没有价值被转移和存储在变量支付中。

我也见过this question,但没有得到任何帮助。

由于我是 MYSQL 和 JSP 的新手,请忽略任何错误。

【问题讨论】:

    标签: java mysql jsp


    【解决方案1】:

    代替

    <% request.setAttribute("acId", "pid"); %> 
    

    使用

    <input id="acId" name="acId" type="hidden" value="<%= pid %>" />
    

    这样在提交时,每一个表单输入元素都会被传递到report.jsp中。

    顺便说一句:你正在使用 while(resultSet.next())... 最好使用 if(resultSet.next())

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-11
      • 1970-01-01
      • 2014-04-17
      • 2013-09-16
      • 2013-12-13
      • 2017-03-02
      • 1970-01-01
      相关资源
      最近更新 更多