JSP&&SERVLET学习笔记(五):请求参数编码处理

package cc.openhome;


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


@WebServlet("/encoding")
public class EncodingServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//Get的编码处理
String name = request.getParameter("nameGet");
name = new String(name.getBytes("IOS-8859-1"), "BIG5");
System.out.println("GET : " + name);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

request.setCharacterEncoding("BIG5");

//Post的编码处理
String name = request.getParameter("namePost");
System.out.println("POST" + name);
}


}

你可能感兴趣的:(JSP&&SERVLET学习笔记(五):请求参数编码处理)