requestDispatcher笔记

    技术2025-05-06  12

    the forward method of the requestDispatcher interface may be called by the calling servlet only when no output has been committd (通过flush方法)to the client.if output data exists in the response buffer that has not been committed,the content must be cleared before the target sevlet's service method is called .if the response has been commited,an exception must be thrown.

     

    //列子

       1. RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/dispatcher");    2.ServletOutputStream sos=response.getOutputStream();   3. sos.write("你好".getBytes());    4.sos.flush();    5.rd.forward(request, response);

     

    当你写了第4行代码时,运行程序会报异常

    当你去掉第4行的时候,response buffer中的内容会被清空

     

    include 无以上 限制

     

     

     

     

    最新回复(0)