Reputation: 2430
I am developing a web service using Eclipse, and in order to try it I launch the tomcat server and try an http request with parameters. The problem is that it seems that the parameters I give are ignored :
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 {
With the debugger, I can see that the object request
doesn't contain my parameters.
Upvotes: 1
Views: 551
Reputation: 40078
You are trying to get HttpSession attribute but not the parameters passed in URL. You need to use
request.getParameter("lat");
Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
To know the difference between session attributes and request params, please refer here
you can also get all parameters in Map
Map<String,String[]> getParameterMap()
Returns a java.util.Map of the parameters of this request.
Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
Upvotes: 1