欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Servlet 传输中文乱码解决方法

程序员文章站 2022-07-14 19:21:34
...

就一句话,而且要用于讲所要转换的变量之下:

name = new String(name.getBytes("iso-8859-1"),"utf-8");

整体代码:

package guigu;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;

public class paramServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("THIS is paramServlet!");
            String name = request.getParameter("username");
            name = new String(name.getBytes("iso-8859-1"),"utf-8");
            String password = request.getParameter("password");
            String[] hobby = request.getParameterValues("hobby");
        System.out.println("用户名:"+name+"   密码:"+password+"   兴趣爱好:"+ Arrays.asList(hobby));
            }



}

结果截图:

Servlet 传输中文乱码解决方法

大体截图:

Servlet 传输中文乱码解决方法 

相关标签: java web