Hello people
I make the following request on the client side
String addr = "blabla:8080/servlet?" + URLEncoder.encode(request, "UTF-8");
URL urlAddr = new URL(addr);
urlAddr.openConnection();
So that a post request is sent to the servlet. lets say my request is ....?request=getUsers&username=bla, which is sent encoded
On the other side I call
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
System.out.println(req.getParameter("request"));
}
prints null. and when I call req.getQueryString() I still get the encoded string. Thats of coruse becase the request contains %3D instead of '='. On the java documentation it says about setCharacterEncoding:
This method must be called prior to reading request parameters or reading input using getReader().
.
Now My question is, what is wrong with this logic?. Of course one can call getQueryString then apply URLDecoder.decode and then parse the string into a Map, but I guess there should be a smarter way to do it
Many thanks