在 Java 中,可以使用 getAttribute 方法检索 HttpServletRequest 对象的属性字段:
String myAttribute = request.getAttribute("[parameter name]");
HttpServletRequest 属性数据存储在原始 HTTP 请求中的什么位置?它在请求正文中吗?
例如,我正在尝试创建一个原始 GET HTTP 请求,该请求将使用某些客户端程序发送到我的 servlet。我的 servlet.doGet() 方法将是这样的:
public void doGet(HttpServletRequest request, HttpServletResponse response)
{
String myAttribute = request.getAttribute("my.username");
...
}
我应该将“my.username”数据放在原始 HTTP 请求中的何处,以便“myAttribute”字符串在归因后接收值“John Doe”?
只是为了澄清,因为我认为@Jon 的回答并没有完全清楚。 HttpServletRequest 上的 getAttribute 和 setAttribute 值并不存在于实际通过线路发送的内容中,它们仅是服务器端的。
// only visible in this request and on the server
request.getAttribute("myAttribute");
// value of the User-Agent header sent by the client
request.getHeader("User-Agent");
// value of param1 either from the query string or form post body
request.getParameter("param1");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)