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?

0

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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. myserver.com:8080/… for the above scenario how we are going to handle it
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: myserver.com:8080/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.