package cn.sasa.serv; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ResServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //设置http响应状态码 //response.setStatus(302);//重定向 //response.sendRedirect("/Web04/ResServlet2"); //设置响应头 //response.setHeader("Location", "/Web04/ResServlet2");//重定向 //response.setHeader("Content-Type", "text/html;charset=UTF-8"); response.setContentType("text/html;charset=UTF-8"); response.setHeader("refresh", "4;url=http://www.baidu.com"); response.setCharacterEncoding("UTF-8"); //响应体 response.getWriter().write("啊啊啊啊"); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }