javaweb请求乱码post
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("/s02")
//请求乱码 Tomcat8以上 get请求不会乱码
//post请求会乱码 通过设置服务器解析的编码的格式
//乱码原因 用的其他编码
//req.setCharacterEncoding(utf-8")
public class servlet02 extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//设置编码格式 放在用之前
req.setCharacterEncoding("UTF-8");
String uname = req.getParameter("uname");
String pwd = req.getParameter("pwd");
System.out.println("姓名:" + uname);
System.out.println("密码:" + pwd);
}
}