package com.mhb;
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 { public void init() throws ServletException {
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
18 //解决乱码方法一:response.setCharacterEncoding("UTF-8");此种方法无效的时候请尝试下一行(19行)的方法。
19 response.setHeader("content-type","text/html;charset=UTF-8");
//获得输出流
PrintWriter out = response.getWriter();
//输出到网页上
out.print("<font color='red'>这是我的第一个示例</font><br>testtest");
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
} public void destroy() {
super.destroy();
}
}