HttpServletRequest
HttpServletResponse
示例
public class ServletTest extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //设置响应类型 response.setContentType("text/html"); //设置字符编码 response.setCharacterEncoding("UTF-8"); //设置响应正文 response.getWriter().print("3秒后跳转到注册页面"); //转发和重定向 request.getRequestDispatcher("http://www.baidu.com").forward(request,response) response.sendRedirect("http://www.baidu.com"); /** * forward和redirect的区别 * forward:是服务器端进行跳转,地址栏不发生变化 * redirect:是客户端获取地址重新进行访问,地址栏发送变化 */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }