JSP的response對象的實例詳解
JSP的response對象的實例詳解
一 response對象
response對象包含了響應(yīng)客戶請求的有關(guān)信息,但在JSP中很少直接用到它。它是HttpServletResponse類的實例。response對象具有頁面作用域,即訪問一個頁面時,該頁面內(nèi)的response對象只能對這次訪問有效,其他頁面的response對象對當(dāng)前頁面無效。
二 response對象常用的方法
三 實戰(zhàn)
<%@ page language="java" import="java.util.*,java.io.*" contentType="text/html; charset=utf-8"%> <% response.setContentType("text/html;charset=utf-8"); //設(shè)置響應(yīng)的MIMI類型 out.println("<h1>response內(nèi)置對象</h1>"); out.println("<hr>"); //out.flush(); //解決PrintWrite對象的瀏覽器輸出總是先于out對象輸出這一問題 PrintWriter outer = response.getWriter(); //獲得輸出流對象 outer.println("大家好,我是response對象生成的輸出流outer對象"); //response.sendRedirect("reg.jsp");//請求重定向 //請求重定向 //response.sendRedirect("request.jsp"); //請求轉(zhuǎn)發(fā) //request.getRequestDispatcher("request.jsp").forward(request, response); %>
四 運(yùn)行結(jié)果
五 小知識總結(jié)
PrintWrite對象的瀏覽器輸出總是先于out對象輸出。
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
在 Linux 上安裝Apache+ApacheJServ+JSP
在 Linux 上安裝Apache+ApacheJServ+JSP...2006-10-10SSM框架JSP使用Layui實現(xiàn)layer彈出層效果
這篇文章主要介紹了SSM框架JSP使用Layui實現(xiàn)layer彈出層效果,文章通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12tomcat6下jsp出現(xiàn)getOutputStream() has already been called for t
這篇文章主要介紹tomcat6下jsp出現(xiàn)getOutputStream() has already been called for this response異常的原因和解決方法,需要的朋友可以參考下。2016-06-06