有关URLEncoder和URLDecoder的一些问题? [英] Some questions about URLEncoder and URLDecoder?

查看:169
本文介绍了有关URLEncoder和URLDecoder的一些问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过了URLEncoder和URLDecoder的javadocs。然后更好奇在任何web应用程序中,每当我们提交
表单时,服务器将表单字段转换为urlencoded字段,当我们执行request.getParamter(fieldName)时。服务器再次使用URLDecoder进行解码。
是否正确?服务器是做这个还是浏览器?当我们在地址栏中输入任何url时,会发生同样的事情吗? 如果服务器或浏览器在URLEncoder和URLDecoder的帮助下明确地编码或解码请求参数,那么
虽然这些是基本问题,但是找不到这些清楚。 / p>

解决方案


在任何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.

这篇关于有关URLEncoder和URLDecoder的一些问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆