简体   繁体   English

是否只有JSP中的POST变量才能使用request.getParameter?

[英]Is there a way to request.getParameter for only POST variables in JSP?

In PHP there is $_REQUEST, $_GET, and $_POST. 在PHP中,有$ _REQUEST,$ _ GET和$ _POST。 What if I want to only get POST variables in JSP to prevent someone from putting the variables in the url? 如果我只想在JSP中获取POST变量以防止某人将变量放在url中怎么办? Is there away to do this? 有没有办法做到这一点? Thanks! 谢谢!

The query string is available from the HttpServletRequest object - so you know what was on the URL. 查询字符串可从HttpServletRequest对象获得-因此您知道URL上的内容。 You can therefore filter out anything in the getParameterMap() that was in the query string, leaving only stuff that was posted. 因此,您可以过滤掉getParameterMap()中查询字符串中的所有内容,仅保留已发布的内容。

Your HttpServletRequest object has a getMethod() property which will tell you if it was a GET or a POST. 您的HttpServletRequest对象具有getMethod()属性,该属性将告诉您它是GET还是POST。 You could just reject all GETs. 您可以拒绝所有GET。

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. 我认为<form action =“ mypage?foo = bar”>不能真正起作用,也就是说,我认为您不能同时拥有POST和GET参数。 I could be wrong, though. 我可能是错的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM