网页和控制台都乱码,post的时候可以,get的时候不可以
package com.yzx.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public MyServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name =request.getParameter("name");
String age = request.getParameter("age");
response.setContentType("text/html;charset=utf-8");
PrintWriter out =response.getWriter();
out.print("name="+new String(name.getBytes("iso-8859-1"),"utf-8")+",age="+age);
System.out.println("name="+new String(name.getBytes("iso-8859-1"),"utf-8"));
System.out.println("age="+age);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}