JSP page include taglib

來源:互聯網
上載者:User

標籤:http   java   使用   io   strong   檔案   資料   for   

page

include

taglib

文法:<%@ 指令名稱 屬性=值 屬性=值 …%>

-------------------

page

1.language 

預設值java

2.extends

3.session

4.import

5.buffer

6.autoFlush

7.IsELIgnored 

false  不忽略

true   忽略,不解析  

8.errorPage 和isErroPage控制JSP頁面發生錯誤跳轉

------------------

PageEncoding

ContentType

編輯JSP的時候,點擊儲存的時候,需要用到PageEncoding,儲存檔案到硬碟

Servlet程式返回給瀏覽器的時候,通過contentType屬性,通知瀏覽器使用哪種編碼去查看網頁。

結論:如果pageEncoding不支援中文,JSP無法將中文資訊儲存到硬碟。

 

------------------

錯誤頁面

一、設定erroPage

二、通過配置web.xml

<erro-page>

     <erro-code>500

     <location>/demo/error.jsp

 

-------------------

include

包含

靜態include原理

index.jsp ---->index_jsp.java

當翻譯到<%@ include file=”header.jsp”%>

翻譯header.jsp,並且將翻譯後的servlet內容引用到index對應的Servlet

靜態包含:包含目標檔案原始碼,原始碼合并到一起,一起進行執行。

 

--------------------

JSP九大內建對象

1.request                    HttpServletRequest

2.response                 HttpServletResponse

3.session                    HttpSession

4.application              ServletContext

5.out                          JspWriter

6.pageContext           PageContext

7.page                        this(HttpServlet)

8.config                      ServletConfig

9.exception                  Throwable

 

pageContext代表當前頁面上下文

向page範圍儲存資料,必須通過它。

pageContext.setAttribute(name,value);

 

findAttribute 方法可以依次在page、request、session、application,四個資料範圍進行資料的尋找

Object value = pageContext.findAttribute(“name”);

 

EL中 直接寫${name}  就會調用findAttribute(),在四個範圍內尋找資料

 

pageContext可以用來獲得其他8個隱含對象

作用:架構的編寫,得到pageContext對象,就相當於得到JSP9個內建對象

 

----------------------

out對象

內部使用PrintWriter實現,擁有獨立緩衝區 8kb

out = pageContext.getOut();

 

-------------------------

out和response.getWriter()的區別

out.print(aaa);

response.getWriter().print(bbb);

out.print(ccc);

結果:

response.getWriter(),輸出的內容在out之前

 

Out緩衝區                           response.getWriter()緩衝區

aaa                                            bbb

ccc

 

為何bbb先輸出?

out必須通過response回寫到瀏覽器,當out.flush,內容輸出到response的緩衝區中。

所以bbb  aaa  ccc

----------------------

exception

使用前要設定isErrorPage=”true”

---------------------------------

 

JSP 6個動作標籤

<jsp:userBean> <jsp: setProperty><jsp:getProperty> 與javaBean有關

<jsp:include> <jsp:forward> <jsp: param>

 

<jsp:include>等價於request.getRequestDispatcher().include

<jsp:forward>等價於request.getRequestDispatcher().forward

 

<jsp:include>功能等價於<%@ include%>

原理:動態包含而不是靜態包含

在index servlet執行的時候,去完成包含動作。包含結果是目標jsp翻譯Servelt產生的html頁面結果

<jsp:forward>等價於 request.getRequestDispatcher(“/”).forward(request, response);

 

---------------------------------------------

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.