有没有办法在 JSP 中仅对 POST 变量进行 request.getParameter ?
在 PHP 中,有 $_REQUEST、$_GET 和 $_POST。如果我只想在 JSP 中获取 POST 变量以防止有人将变量放入 url 中怎么办?有办法做到这一点吗?谢谢!
In PHP there is $_REQUEST, $_GET, and $_POST. What if I want to only get POST variables in JSP to prevent someone from putting the variables in the url? Is there away to do this? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查询字符串可从 HttpServletRequest 对象中获取 - 因此您知道 URL 上的内容。因此,您可以过滤掉 getParameterMap() 中查询字符串中的任何内容,只留下已发布的内容。
The query string is available from the HttpServletRequest object - so you know what was on the URL. You can therefore filter out anything in the getParameterMap() that was in the query string, leaving only stuff that was posted.
您的 HttpServletRequest 对象有一个 getMethod() 属性,它会告诉您它是 GET 还是 POST。您可以拒绝所有 GET。
我不认为
Your HttpServletRequest object has a getMethod() property which will tell you if it was a GET or a POST. You could just reject all GETs.
I don't think that <form action="mypage?foo=bar"> actually works, that is, I don't think you can have both POST and GET parameters at the same time. I could be wrong, though.