当我点击 jspA 中的链接时,它将使用查询字符串src重定向到 jspB。 src 的消息将毫无问题地显示在 jspB 中。但是,为什么我尝试单击提交,却无法在 servlet 页面中检索 src 的值。有没有办法让我在 servlet 中检索 src 的值?谢谢。
在我的 jspB 页面内:
<img src="<%= request.getParameter("src") %>" />
<table>
<form name="frmTest" action="test" method="post">
<input type="submit" value="sub" name="sub" />
</form>
</table>
在我的 Servlet 测试中:
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException{
String imgUrl = req.getParameter("src");
我正在从 imrUrl 检索空值。
最佳答案
当您提交 html form
时,仅将 input
和 select
元素作为参数发送。您没有将 name
属性设置为 src
的任何内容。
您可以使用隐藏的输入
<form name="frmTest" action="test" method="post">
<input type="submit" value="sub" name="sub" />
<input type="hidden" name="src" value="<%= request.getParameter("src") %>" />
</form>
It is generally discouraged to use scriptlets.阅读 JSTL 和 EL 并使用这些技术。
关于java - 从 JSP 检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18937405/