引入:
在jsp開發(fā)有些對象使用頻率比較高,(例如:requesst,respone,session,servletcontext陆赋。。嚷闭。)如果每次要使用這些對象都自己去獲取對象才能使用攒岛,會顯示太麻煩了。jsp把這些對象都創(chuàng)建或獲取好了胞锰,我們開發(fā)者之間使用這些對象即可T志狻!嗅榕!這些對象就叫做內(nèi)置對象
九大內(nèi)置對象:
jsp對象名 | 類型 |
---|---|
request | HttpServletRequest |
response | HttpServletResponse |
config | ServletConfig |
application | ServletContext |
session | HttpSession |
exception | Throwable |
page | Object |
out | JspWriter |
pageContext | PageContext |
out對象:
我們都知道response.getWriter().write()可以往瀏覽器中寫入實體內(nèi)容顺饮;那么out對象的writer()方法與如上方法有什么不同呢?
Paste_Image.png
Paste_Image.png
Paste_Image.png
pageContext對象:
<body>
<%--可以獲取其他內(nèi)置對象 --%>
<%
//pageContext.getResponse().getWriter().write("來啊凌那,愛情啊");
%>
<%--可以作為域?qū)ο?--%>
<%
// pageContext.setAttribute("name", "丁昌江");
// out.write((String)pageContext.getAttribute("name"));
%>
<%--可以保存數(shù)據(jù)到其他域?qū)ο?request,session,application)
注意:在哪個域?qū)ο笾写鎯?shù)據(jù)就應(yīng)該在哪個域?qū)ο笾凶x取數(shù)據(jù)
--%>
<%
pageContext.setAttribute("name", "request-丁昌江",pageContext.REQUEST_SCOPE);
//out.write((String)pageContext.getAttribute("name",pageContext.REQUEST_SCOPE));
out.write((String)request.getAttribute("name"));
%>
</body>