2

I am developing an App where I am sending get request to REST web service using @RequestMapping(value = "myURLpattern", method = RequestMethod.GET, produces = "image/png")

I came across a bug if somebody enters # in the URL query String it breaks from there http://myserver.com:8080/csg?x=1&y=2#4&z=32&p=1

So I tried to encode it via filter HTTPRequestWrapper so that # will be replaced by %23 using URLEncoder.

My problem is for encoding URL, first I need to read the URL(request.getRequestURL()). and getURL again can't read string after #. request.getRequestURL() will return only (http://myserver.com:8080/csg?x=1&y=2)

Is there any other way to parse the complete url and encode it before sending to REST web service?

giampaolo
  • 6,906
  • 5
  • 45
  • 73
Krishna
  • 179
  • 3
  • 17

1 Answers1

3

That is not a bug. Check this:

What is the meaning of # in URL and how can i use that?

A # in the url query string is wrong. You should encode it on client side, before sending it to your server. See this one: How to pass '#' in query string It is in asp, but you should find the java equivalent.

Something to get you started can be this one Java URL encoding of query string parameters

Community
  • 1
  • 1
Nikola Yovchev
  • 9,498
  • 4
  • 46
  • 72
  • Thanks for your reference so if some one enters # in one of Html field like serial number:12#ser4 then we can not parse it on server side. http://myserver.com:8080/csg?serial=12#ser4&manufacture=12-07-2013&warranty=3 for the above scenario how we are going to handle it – Krishna Sep 09 '13 at 18:02
  • Encode it on the client side. Take a look at encodeURIComponent function in javascriopt. encodeURIComponent('12#ser4'); would make '12#ser4' become '12%23ser4' which is what you should be sending to the server, so your request would look like that: http://myserver.com:8080/csg?serial=12%23ser4&manufacture=12-07-2013&warranty=3 – Nikola Yovchev Sep 10 '13 at 07:38