Jsp/Servlet澶嶄範绗旇-----绗?绔?JSP琛ㄨ揪寮忚瑷€
8.1 琛ㄨ揪寮忚瑷€绠€浠?
JSP鐢ㄤ簬鍦ㄧ綉椤典笂鏄剧ず鍔ㄦ€佸唴瀹癸紝閫氬父闇€瑕佸湪JSP椤甸潰涓祵鍏ava鑴氭湰浠ュ畬鎴愬鏉傚姛鑳姐€備絾鏄ぇ閲忕殑Java鑴氭湰浣垮緱JSP椤甸潰闅句互缁存姢銆備竴绉嶇被浼糐avaScript璇█鈥擩SP琛ㄨ揪寮忚瑷€鍙敤浜庡湪缃戦〉涓婄敓鎴愬姩鎬佸唴瀹癸紝骞朵唬鏇縅SP鑴氭湰鍏冪礌銆侸SP琛ㄨ揪寮忚瑷€鏄粠JSP2.0瑙勮寖寮€濮嬫敮鎸佺殑鎶€鏈€?
8.2 绂佺敤EL 琛ㄨ揪寮忚绠?
8.3 鍙橀噺
8.4 闅愬紡瀵硅薄
8.5 鏂囧瓧甯搁噺
8.6 杩愮畻绗?
8.7 淇濈暀瀛?
8.8 琛ㄨ揪寮忎娇鐢ㄦ渚?
8.9 鏈珷灏忕粨
EL鐨勪富瑕佸姛鑳斤細
绮剧‘鐨勮闂瓨鍌ㄥ璞?
Bean灞炴€х殑绠€鐣ヨ娉?
绌哄€煎彇浠i敊璇秷鎭?
涔嬪墠浠g爜锛?
Java浠g爜
1.<%
2. pageContext.setAttribute("name","darkness");
3.%>
4.<%
5. if(pageContext.getAttribute("name") != null)
6. {
7.%>
8. <%=pageContext.getAttribute("name")%>
9.<%
10. }
11.%>
12.
13.<!--鍙互鍙戠幇锛岃繖鏍凤紝浠g爜杈冨-->
14.<%
15. pageContext.setAttribute("name","darkness");
16.%>
<%
pageContext.setAttribute("name","darkness");
%>
<%
if(pageContext.getAttribute("name") != null)
{
%>
<%=pageContext.getAttribute("name")%>
<%
}
%>
<!--鍙互鍙戠幇锛岃繖鏍凤紝浠g爜杈冨-->
<%
pageContext.setAttribute("name","darkness");
%>
${name}
浣跨敤琛ㄨ揪寮忔椂涓嶉渶瑕佸幓鍒ゆ柇灞炴€ф槸鍚︿负绌?
Java浠g爜
1.<!--濡傛灉鍦ㄤ笉鍚岀殑灞炴€ц寖鍥翠腑璁剧疆浜嗗悓鍚嶇殑灞炴€э紝鍒欎箣鍚庣殑鍚屽悕灞炴€ф棤娉曟壘鍒?->
2.<!--鎸夌収鍥涗腑鏍囧織浣嶆潵瀵绘壘-->
3.<%
4. pageContext.setAttribute("name","darkness");
5. request.setAttribute("name","darkness");
6.%>
7.${name}
<!--濡傛灉鍦ㄤ笉鍚岀殑灞炴€ц寖鍥翠腑璁剧疆浜嗗悓鍚嶇殑灞炴€э紝鍒欎箣鍚庣殑鍚屽悕灞炴€ф棤娉曟壘鍒?->
<!--鎸夌収鍥涗腑鏍囧織浣嶆潵瀵绘壘-->
<%
pageContext.setAttribute("name","darkness");
request.setAttribute("name","darkness");
%>
${name}
EL鐨勪富瑕佸姛鑳藉湪浜嶮VC璁捐妯″紡涔嬩腑
鍚庡彴锛?
Java浠g爜
1.package org.sky.darkness.servlet.el ;
2.
3.import java.io.* ;
4.import javax.servlet.* ;
5.import javax.servlet.http.* ;
6.
7.public class ELServletDemo01 extends HttpServlet
8.{
9. public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
10. {
11. req.setAttribute("name","www.sky.org") ;
12. // 鏈嶅姟鍣ㄧ璺宠浆
13. req.getRequestDispatcher("eldemo03.jsp").forward(req,resp) ;
14. }
15. public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
16. {
17. this.doGet(req,resp) ;
18. }
19.};
20./*
21. <servlet>
22. <servlet-name>el01</servlet-name>
23. <servlet-class> org.sky.darkness.servlet.el.ELServletDemo01</servlet-class>
24. </servlet>
25. <servlet-mapping>
26. <servlet-name>el01</servlet-name>
27. <url-pattern>/eldemo