码迷,mamicode.com
首页 > 其他好文 > 详细

request的细节--学习笔记

时间:2018-04-18 16:25:50      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:request的细节--学习笔记

  • )转发是通过RequestDispatcher对象的forward(request,response)方法完成的
  • )forward()方法之前的输出,如果是输出到缓冲区,再转发到其他Servlet,那么原缓冲区的数据忽略不计
  • )forward()方法之前的输出,如果真正输出到浏览器,再转发到其他Servlet,再转发到其他Servlet代码忽略不计
  • )forward()方法之前的输出,如果是对响应头的设置,会保留到转发的其他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 Demo91 extends HttpServlet {
        public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
            //response.setContentType("text/html;charset=UTF-8");
            //PrintWriter pw = response.getWriter();
            //pw.write("Demo91");
            //pw.flush();
            //pw.close();
            //转发
            //request.getRequestDispatcher("/Demo92").forward(request,response);
            //重定向
            response.sendRedirect("/day06/success.html");
        }
    }
    

    转发java

    
    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 Demo92 extends HttpServlet {
        public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
    
             //输出
            response.getWriter().write("Demo92");
        }
    }

    request的细节--学习笔记

    标签:request的细节--学习笔记

    原文地址:http://blog.51cto.com/357712148/2104943

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    登录后才能评论!
    © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
    迷上了代码!