Java 请求.getParameter
确认:我们可以传入Controller然后输出回jsp,我们将使用 model.addAttribute("abc", abc); ==>爪哇 request.getParameter("abc"))) ==>; JSP
但我不知道如何使用 getParameter?
有时我可以获得 request.getParameter("abc") 值,有时可能不会。
我已经比较了两者:工作的和不工作的。
两者都有 HttpSession 会话,但不起作用的一个仍然不起作用。
我可以知道什么问题吗?
谢谢 -fsloke
Confirm : We can pass in the Controller then output back to jsp , we will use
model.addAttribute("abc", abc); ==> JAVA
request.getParameter("abc"))) ==> JSP
But I not sure how to use getParameter?
Sometime I can get request.getParameter("abc") value, sometime may not.
I already compare both : the working one with not working one.
Both have HttpSession session But the not work one still not working.
May I know what problem?
Thanks
-fsloke
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会冒险猜测一个解决方案,尽管我不确信我完全理解你的问题。
根据您所说的,您似乎很困惑,有时
request.getParameter("abc")
返回一个值,有时则不返回。此方法查找传入请求中的参数 - 因此,仅当传入请求的查询字符串(或 POST 数据)上指定了参数时,它才会返回一个值。听起来您可能认为这会根据您的第五段从会话中查找一些内容。但是会话的存在与传入请求上可用的参数完全无关。如果您想从会话中查找某些内容,则应该调用
session.getAttribute("abc")
。I'll hazard a guess at a solution, though I'm not convinced I understand your problem in its entirety.
Based on what you're saying, it seems like you're confused that sometimes
request.getParameter("abc")
returns a value, and sometimes it does not. This method looks up the parameters from the incoming request - so it will return a value only if there was one specified on the query string (or POST data) of the incoming request.It sounds like you might have thought that this looks up something from the session, based on your fifth paragraph. But the existence of a session is completely unrelated to what parameters are available on an incoming request. If you want to look up something from the session, you should call
session.getAttribute("abc")
instead.