請(qǐng)問(wèn),為何有out.flush();語(yǔ)句,頁(yè)面就不能重定向頁(yè)面呢?
<%@?page?language="java"?import="java.util.*,java.io.*"?contentType="text/html;?charset=utf-8"%> <% response.setContentType("text/html;charset=utf-8"); out.print("<h1>response內(nèi)置對(duì)象</h1>"); out.print("<hr>"); out.flush(); PrintWriter?outer=response.getWriter(); outer.println("大家好,我是response對(duì)象生成的輸出流outer對(duì)象"); response.sendRedirect("reg.jsp");//請(qǐng)求重定向 %>
2015-06-12
使用out.flush()語(yǔ)句會(huì)拋出異常,導(dǎo)致后面的代碼不能執(zhí)行,也就不能重定向頁(yè)面了。你可以自己運(yùn)行一下代碼,不給flush加注釋,看看會(huì)有什么問(wèn)題:)
2016-01-13
看了樓上的還是沒(méi)有明白。out和response的printwriter應(yīng)該是兩個(gè)不同的輸出對(duì)象。out.flush應(yīng)該是清空out對(duì)象的輸出,為什么response對(duì)象的輸出也會(huì)被清空?