Serlet输出中文、感叹号乱码等的解决办法

2/22/2017来源:ASP.NET技巧人气:3145

import java.io.IOException; import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import java.io.PRintWriter; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; public class PrintToBrowser implements Servlet { public void destroy(){} public ServletConfig getServletConfig(){return null;} public  String getServletInfo(){return null;} public  void init(ServletConfig config)throws ServletException{} public void service(ServletRequest req, ServletResponse res)throws IOException, ServletException {req.setCharacterEncoding("utf-8");    res.setContentType("text/html;charset=utf-8");    res.setCharacterEncoding("utf-8");           PrintWriter out=  res.getWriter(); out.print("<html>"); out.print("<body>");          out.print("<h1 align='center'><font color='red'> Welcome Page!!!谢谢</font></h1>");   out.print("</body>"); out.print("</html>");  }

}