URLEncoder.encode:
这是编码:
这是编码:
如:
1、要把文本框中中的内容存到cookie里面,由于cookie是ASCLL编码方式,所以要把文本框中的内容编码到ascll,便于存到cookie(在这里没有存入cookie的代码)
如:
其中name为文本框中的文字的name
在login.jsp中:
用户名:<input name="username">在2.jsp中:
String name = request.getParameter("username"); //首先把文本框中的内容找到
String newName = URLEncoder.encode(name); //把文本框中utf-8类型转换成ASCLL码,便于存到cookie(在这里没有存入cookie的代码)
URLDecoder.decode:
这是解码,把ASCLL类型转换成utf-8类型,否则如果是ASCLL码不支持的类型,将出现乱码
name1= URLDecoder.decode(name); //将ASCLL编码转换成utf-8,(name为从cookie中取出来的值,为ASCLL编码方式)现在name1为utf-8编码方式。
以上转码方式常常用在cookie和session的结合使用中
本文介绍了如何使用URLEncoder.encode和URLDecoder.decode进行编码与解码操作,以解决cookie存储中文等特殊字符的问题,并探讨了其在cookie和session结合使用中的应用场景。
1万+

被折叠的 条评论
为什么被折叠?



