java中url编码算法,Java中的URL编码?

I want to know that what is url encoding.

I have 2 jsp pages and one servlet.

When I run the application the url displayed is :

http://localhost:8080/myproject/index.jsp

where

index.jsp :

after the submit button is clicked the URL displayed is :

http://localhost:8080/myproject/Myservlet

What is the meaning of URL encoding? How can I encode url?

From index.jsp goes to Myservlet then to result.jsp

Myservet#doPost // Do I need to do URL encoding here? If yes how ?

fetching data from db.......

....................

String nextJSP = "/result.jsp";

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);

dispatcher.forward(request,response);

result.jsp

displays data here

解决方案

There are two types of encoding: HTML form encoding and URL re-writing.

In form encoding, the URL string is converted into a valid ASCII format that's Internet-ready. From the URLEncoder.encode(String, String) docs:

Translates a string into application/x-www-form-urlencoded format

using a specific encoding scheme. This method uses the supplied

encoding scheme to obtain the bytes for unsafe characters.

The second kind is URL rewriting. The URL string is encoded with a session id in case the client browser doesn't support (or has disabled) cookies or session tracking. From the HttpServletResponse.encodeURL(String) docs:

Encodes the specified URL by including the session ID in it, or, if

encoding is not needed, returns the URL unchanged. The implementation

of this method includes the logic to determine whether the session ID

needs to be encoded in the URL. For example, if the browser supports

cookies, or session tracking is turned off, URL encoding is

unnecessary.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值