且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有关URLEncoder和URLDecoder的一些问题?

更新时间:2023-09-29 22:32:52


在任何web应用程序中,只要我们提交表单,服务器将表单域转换为urlencoded字段,我们请request.getParamter(fieldName)。


否。浏览器会这样做。


服务器再次使用URLDecoder进行解码。这是正确的吗?



服务器是做还是浏览器?


浏览器。


如果我们需要在URLEncoder和URLDecoder的帮助下明确地对请求参数
进行编码或解码,那么服务器或浏览器是否这样做?'


我不知道这是什么意思,但它仍然是浏览器。如果从应用程序代码发送请求,则只需要对请求参数进行编码。如果你正在运行一个servlet容器,你根本不需要解码它们:它会为你做的。


I have gone thru javadocs of URLEncoder and URLDecoder. Then got more inquisitive. Consider the server as tomcat.In any webapplication whenever we submit the form , server converts the forms fields into urlencoded fields and when we do request.getParamter("fieldName"). Server again decode it with URLDecoder. Is that correct? Does server do it or browser? Simlary when we type any url in address bar same stuff happens? If server or browser does that when we require to encode or decode the request paramter explicitly with the help of URLEncoder and URLDecoder? Though these are basic questions but could not find these anwers clearly.

In any webapplication whenever we submit the form , server converts the forms fields into urlencoded fields and when we do request.getParamter("fieldName").

No. The browser does that.

Server again decode it with URLDecoder. Is that correct?

Yes.

Does server do it or browser?

The browser.

If server or browser does that when we require to encode or decode the request parameter explicitly with the help of URLEncoder and URLDecoder?'

I don't know what that means but it's still the browser. You only need to encode the request parameters if you are sending the request from application code. You don't need to decode them at all if you're running in a servlet container: it will do that for you.