我在将属性放回 java 请求中时遇到问题。 基本上我有一个 jsp 从该页面的链接中获取“id”:
Integer prodId = Integer.parseInt(request.getParameter("productId"));
然后在我的命令中(我使用命令模式)我从请求中获取“id”,然后返回到同一个 jsp 页面,但随后“id”不再在请求中,我得到一个数字格式异常
我已经尝试过:
request.setAttribute("prodId", id);
但没有效果
有人有什么想法吗?
谢谢。
最佳答案
请求属性和请求参数是不同的东西。
1.尝试将其检索为:
request.getAttribute("prodId");
从 JSP 中,在命令类中设置请求属性后,如下
request.setAttribute("prodId", id);
此代码获取请求参数,而不是请求属性。
request.getParameter("productId");
2.或者,如果您从 Command 类转发到 JSP 页面:
//this will let you use request.getParameter() in JSP.
request.getRequestDispatcher(jspFilePath).forward(request,response);
关于java - 将属性放回到java中的请求中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16303218/