java url中文 编译和解码

时间:2023-03-08 17:03:52

js到servlet:

js端

var minename='中文';

minename=encodeURI(encodeURI(minename));

java servlet 端

String name=request.getParameter("minename");//获取页面请求
name= URLDecoder.decode(name, "UTF-8");

java 获取API时:

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder; public class Java_ZhuanMa { public static void main(String[] args) throws UnsupportedEncodingException {
String name="柠条塔煤矿";
System.out.println(URLEncoder.encode(name,"UTF-8"));//中文编译
System.out.println(URLDecoder.decode(URLEncoder.encode(name,"UTF-8"), "UTF-8"));//解密编译文件 } }