http Java web服务请求参数返回为null
我正在使用Eclipse开发一个web服务,为了尝试它,我启动了tomcat服务器,并尝试了一个带有参数的http请求。问题是,我给出的参数似乎被忽略了:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
if(session.getAttribute("lat") == null && session.getAttribute("lon") == null) {
session.setAttribute("lat", request.getAttribute("lat"));
session.setAttribute("lon", request.getAttribute("lon"));
response.setContentType("text/plain");
response.getWriter().append("RECEIVED");
}
else {
通过调试器,我可以看到对象request
不包含我的参数
# 1 楼答案
您正在尝试获取HttpSession属性,但无法获取URL中传递的参数。你需要使用
要了解会话属性和请求参数之间的区别,请参阅here
您还可以在
Map
中获取所有参数