URLDecoder.decode与URLEncoder.encode

    xiaoxiao2021-03-25  106

    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的结合使用中

    转载请注明原文地址: https://ju.6miu.com/read-5179.html

    最新回复(0)