0

In my jetty server log, I observe the following:

07 Jan 2016 10:03:52,605 DEBUG WS.DuccHandlerProxy - N/A handle (GET /ducc-servlet/file-contents?fname=/home/degenaro/ducc/logs/1/x+y+z.log&page=1)

07 Jan 2016 10:03:52,605 DEBUG WS.DuccHandler - N/A handleDuccServletFileContents qs:fname=/home/degenaro/ducc/logs/1/x+y+z.log&page=1

07 Jan 2016 10:03:52,605 DEBUG WS.DuccHandler - N/A handleDuccServletFileContents fn:/home/degenaro/ducc/logs/1/x y z.log

The code corresponding to the last two entries comprise the results of request.getQueryString() and request.getParameter("fname") respectively.

How come the latter loses the '+' character?

user2133121
  • 341
  • 1
  • 3
  • 12

1 Answers1

0

When you call request.getQueryString() you get the query string as it is in the url bar. When you call request.getParameter("fname") you get the value of that parameter with any encoded symbols decoded. + in a url parameter represents a space, so its decoded to space.

developerwjk
  • 8,619
  • 2
  • 17
  • 33
  • Thanks! So if the input is immutable, then I suppose I'll have to parse the query string myself and abandon use of request.getParameter()? – user2133121 Jan 07 '16 at 15:49
  • @user2133121 Do you want the literal `+`? If you created the link, you should use urlencode function on the parameter when building the link. (It would replace `+` with `%2B` which will be translated back to literal `+` by `request.getParameter("fname")` – developerwjk Jan 07 '16 at 15:51
  • Changing the request is not my first choice. And what other characters do I need to watch out for? I did find HttpServlet documentation http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getParameter%28java.lang.String%29 which makes no mention of the different behaviours between these two methods. – user2133121 Jan 07 '16 at 15:56
  • The answer to my question is here https://en.wikipedia.org/wiki/Percent-encoding which I hope will help someone else someday. – user2133121 Jan 07 '16 at 18:45