<td> 在 Java 中获取值 - request.getParameter



我试图获取一些td元素的值,其中数据由MySQL表中的数据组成。它在我的浏览器中很好地显示数据(例如,如果我将类型从"隐藏"更改为"提交"(,但是当我尝试获取值时,我只会得到 null。

这是我的jsp,它在浏览器中显示正确的结果。

<td>
<form action="history.jsp" method="get">
<input type="hidden" name="res" value="<%=his.getRes()%>"/>
</form>
</td>

但是,当我尝试打印值时,我只在 evey 得到"null":

<% 
String res = request.getParameter("res");
System.out.print(res);
%>

我仍然很新,所以这可能是一个直截了当的答案。提前感谢您的帮助。

我建议你更改变量的名称:

String newname = request.getParameter("res");
System.out.println(newname)
  • 一个人只能提交(=发送(一个<form>。因此,必须假设只有一个td与一个<form>。表单也不能嵌套在外部表单中。

  • 它需要某种方式来提交表单。

因此,请先尝试:

<td>
<form action="history.jsp" method="get">
<input type="text" name="res" value="<%=his.getRes()%>"/>
<input type="submit" value="Send"/>
</form>
</td>

这将显示his.getRes()是否产生了一些东西。并允许在浏览器中手动提交。

最新更新