开发者

Java : When a parameter has a value that matches a UTF-8 encoded string in a java HTTPRequestServlet, a doGet decodes it by default

I am new to servlets. I issue a GET request on a servlet with a parameter say param=https%3A%2F%2Fwww.somesite.com from the client side. On the server side, there is a doGet method that takes HTTPServletRequest and HTTPServletResponse object. When i try to retr开发者_开发问答ieve param, it gives me https://www.somesite.com instead of https%3A%2F%2Fwww.somesite.com.

The server side code runs on Websphere. Is it an expected behavior or is there any possible explanation for the same ?


This is expected behaviour. All parameters passed via GET must be encoded and you will likely need to decode them manually anyway, so servlet does this job for you. If you do not need this, you may use java.net.URLEncoder.encode(<your_string>, "UTF-8")


This is the correct behaviour exmplined in qoutes you put as your question's subject.

URL is restricted for using some characters. You can only use English letters, digits and some special characters. If you have to send other symbols they have to be encoded using the % notation. For example %20 means space, %3A means colon etc. The encoding is done by client. For convenience servlet API decodes servlet parameters automatically.

This is what you read in documentation and see in action.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜