hello阿诚

有兴趣留言交流

05-解决请求乱码问题,tomcat服务器

package com.resquest;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ser02")
public class servlet02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest reqHttpServletResponse respthrows ServletExceptionIOException {
        System.out.println("解决乱码问题");
        //解决 post 乱码问题
        req.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        String psd = req.getParameter("psd");
        System.out.println("name"+name+"psd"+psd);


    }
    /* 解决乱码 问题
        tomcat 8          tomcat 7
get 方法 不会乱码            会出现乱码
                            new String(req.getParameter(name).getBytes("ISO-8859-1"),"UTF_8")
                            针对任意请求方式,但是如果不乱码,使用后就会出现乱码

post 方法 会乱码             会乱码
        req.setCharacterEncoding("UTF-8");

     */
}


posted on 2021-07-15 14:17  陆秋明v  阅读(42)  评论(0编辑  收藏  举报

导航