涓???Jsp
???????1??Jsp 锛?Java Server Pages锛?锛?瀹??? Servlet ????涓??凤??芥?? SUN ???稿??涔???涓?绉??ㄤ?寮????ㄦ?? Web 璧?婧?????????
????????? Jsp ??????璁稿?ㄩ〉??腑宓?濂? Java 浠g??锛?骞朵???璁稿???浜哄???ㄩ〉??腑?峰?? request??response 绛? Web 甯哥?ㄥ?硅薄??瀹??版???″?ㄤ?娴?瑙??ㄤ??寸??浜や?锛???浠?Jsp 涔???涓?绉??ㄦ?? Web 璧?婧???寮?????????
????????? 2??Jsp ???ц?杩?绋???褰??ㄦ?风??涓?娆¤?块??涓?涓? Jsp 椤甸?㈡?讹????″?ㄤ?灏? Jsp ????瀹圭炕璇?涓轰?涓? Servlet锛??跺??灏?瀛???????婧???浠跺???惧?ㄦ???″??work ??褰???涓绘?虹??褰?涓??????″?ㄩ??杩? Servlet 灏? Jsp 椤甸?㈢????瀹归??杩? out 瀵硅薄杈??哄?板?㈡?锋?虹??娴?瑙??ㄤ腑??褰? Jsp ??宓?浜? Java 浠g???讹????″?ㄤ???灏?涓??ㄧ??灏? Java 浠g??浜ょ? Servlet ?ц???濡??????″?ㄤ腑宸茬?瀛??ㄤ?缂?璇?濂界?? Servlet 瀛?????锛??d??ㄦ?峰??璁块?? Jsp ???跺??锛??跺??涓???璁块???? Jsp ?????存?ヨ?块?? Servlet??
????????? 3??Jsp ??涔?澶ч??寮?瀵硅薄锛?
??????????????? (1) request锛?灏?瑁?浜??ㄦ?锋??浜や俊??? ---锛??ㄦ?疯?锋??? Request锛?
??????????????? (2) pageContext锛?灏?瑁?浜??跺??????瀵硅薄??--- 锛?椤甸?㈡?ц????Page锛?
????????????????(3) session锛??ㄧ?ㄦ?烽?娆¤?块???惰?峰?????涓?涓? Jsp ????缃???瀵硅薄??--- 锛??翠釜浼?璇??? Session锛?
??????????????? (4) application锛????″?ㄥ???ㄦ?跺??寤虹?? ServletContext 瀵硅薄??涔?灏辨??涓?涓? Web 搴??ㄣ??--- 锛??翠釜搴??ㄨ?琛??? Application锛?
??????????????? (5) out锛???瀹㈡?锋?鸿??烘?版????娴?瀵硅薄???ㄤ???绉??版????杈??恒?????ㄦ??涓?涓? JspWriter锛?榛?璁ょ?瀛?澶у?涓?8kb??--- 锛?椤甸?㈡?ц????Page锛?
????????????????(6) config锛???缃? Servlet 锛?璇ュ?硅薄?ㄤ?瀛???servlet瀹?渚?????濮??????般????--- 锛?椤甸?㈡?ц????Page锛?
??????????????? (7) page锛???褰??? Jsp 椤甸???绛???浜? Servlet 涓??? this ?抽??瀛?锛?琛ㄧず浠?璇ラ〉??骇????涓?涓?servlet瀹?渚?????--- 锛?椤甸?㈡?ц????Page锛?
???????????????(8) response锛?瀵瑰?㈡?风??璇锋????哄?ㄦ????搴?锛???瀹㈡?峰?????版???? --- 锛?椤甸?㈡?ц??? Page锛?
??????????????? (9) exception锛?寮?甯搞????--- 锛?椤甸?㈡?ц????Page锛?
?????????? 4??Jsp ??浣冲??璺?
???????????????? Servlet ??璐?璐e??搴?璇锋?浜х???版??锛?骞舵???版????杩?杞???????甯?? Jsp锛?Jsp ???ㄤ??版?????剧ず??
浜???Jsp 璇?娉?
????????1??Jsp 妯$????绱???Jsp 椤甸??腑?? HTML ??瀹圭О涓?Jsp 妯$????绱???Jsp 妯$????绱?瀹?涔?浜?缃?椤电???烘??楠ㄦ?讹??冲??涔?浜?椤甸?㈢??缁?????澶?瑙???
?????????? 2??Jsp ????琛ㄨ揪寮???<%= 琛ㄨ揪寮?%>??褰????堕?达?<%= new Date().toLocalString()%>??
???????????3??Jsp ??????娈点???ㄤ??ㄩ〉?㈠?????ュ?琛? Java 浠g???? <%???Java 浠g??? %>
?????????? 4??Jsp 澹版????Jsp 椤甸??腑??缂?????浠g??浼?榛?璁ょ??缈昏????Servlet 涓??? service 涓?锛??? Jsp 澹版??涓???? Java 浠g??琚?缈昏????_jspService ?规???澶??????冲??涔?浜? Servlet ???ㄥ????????规???????浠g???????变? Jsp ????寮?瀵硅薄????service ?规?涓????界??锛???浠ュ??Jsp 澹版??涓?瀹?涔???????涓??借?块????
??????????? 5??Jsp ??浠ゃ??Jsp ??浠ゆ??涓烘???″?ㄨ??璁捐?$??锛?瀹?浠?骞朵??存?ヤ骇??浠讳???瑙?杈??猴???????璇????″?ㄥ?浣?澶???? Jsp 椤甸??腑???朵??ㄥ?????
?????????????????? <%@ ??浠?灞??у??="???%> 渚?濡?锛?<%@ contextType="text/html charset=gb2312"?%>
?????????????????? (1) page ??浠ゃ??page ??浠ょ?ㄤ?瀹?涔? Jsp 椤甸?㈢????绉?灞??э???璁?page ??浠ゅ?虹?板??Jsp 椤甸??腑??浠?涔?浣?缃?锛?瀹?浣??ㄧ???芥?? Jsp 椤甸????
???????????????????????? <%@ page
????????????????????????????????????[language="java"]???? //?ㄤ???瀹?褰???椤甸?㈠??宓????? Java 浠g????
??????????????????????????????????? [extends="package.class"]??? ?//?ㄤ???瀹?缈昏?????? Servlet 缁ф?垮??涓?绫汇??
????????????????????????????????????[import="java.io.*"]? ?? //?ㄤ?瀵煎??Java 浠g??????瑕?????锛???涓?涔??寸?? , "?峰???诧?涔???浠ュ??寮?????
????????????????????????????????????[session="true | false"]???? //??瀹?缈昏?????? Servlet ???????ㄥ??寤?Session 瀵硅薄锛?榛?璁ゅ?间负 true????浠?甯稿父瑕?缃?涓?false????涓?Session ??????杈??匡???浠ユ??浠?涓???瑕? Session 瀵硅薄???跺??灏变?瑕???寤猴?浠ュ??杞绘???″?ㄥ??????
????????????????????????????????????[buffer="none | 8kb | sizekb"]??? ?//?ㄤ???瀹? out 瀵硅薄??浼??插?哄ぇ灏?锛?涔?灏辨?? JspWriter ??缂??插?哄ぇ灏?锛?榛?璁や负 8kb??
????????????????????????????????????[autoFlush="true | false"]???? //??瀹?涓???buffer 缂??插?烘???????ㄥ?锋?帮?榛?璁や负 true??
????????????????????????????????????[isThreadSage="true | false"]???? //榛?璁ゅ?间负 true锛????ㄧ户??SingleThreadModel ??璁版?ュ?g???瑰?瀹??般??
????????????????????????????????????[info="text"]???? //??瀹?褰???椤甸??俊??涓烘??????
????????????????????????????????????[errorPage="error.index"]???? //??瀹???璇?淇℃??椤甸????朵腑??瀹? URL ????褰?蹇?椤讳娇?ㄧ?稿?硅矾寰?锛?濡???浠?"/" 寮?澶达??d?琛ㄧず?稿?逛?褰??? Web 搴??ㄧ?搴????圭??褰?锛?涓???绔??圭???圭??褰???璁剧疆??璇?椤甸?㈢?????绉??瑰?锛???web.xml ??缃???浠朵腑锛?<web-app> ??绱?涓????ュ????绱?锛?
????????????????????????????????????????????????? <exception-type>寮?甯哥被???ㄩ??瀹???</excetion-type> ???? <error-code>??璇???lt;/error-code>
???????????????????????????????????????????????????<location>??璇?淇℃???剧ず椤甸??lt;/location> 娉ㄦ??锛???璇?椤甸?㈢??澶у?蹇?椤昏?杩? 1kb ???芥?e父?剧ず??濡?????web.xml ??浠朵腑??缃?浜???璇?淇℃??椤甸????d???Jsp 涓?璁剧疆?? errorPage ??浠ゅ?涓?璧蜂??ㄣ??浼?????璇?淇℃??灏辨???ㄥ?颁? exception ??寮?瀵硅薄??
???????????????????????????????????? [isErrorPage="true | false"]???? //??瀹?杩?涓?椤甸?㈡????负????澶???椤甸???濡???????璇???濂芥?逛负 true??
???????????????????????????????????? [contentType]???? //??瀹?椤甸?㈢?? MIME 绫诲??锛?璇存??椤甸?㈡??浠?涔?椤甸???椤甸?㈤???ㄤ?涔?缂????瑰????朵腑 charset ?ㄤ?璇存?? Jsp 婧???浠跺??绗????????????????缁?瀹㈡?锋?虹???跺?????ㄤ?涔?缂????瑰???
?????????????????????????????????????[pageEncoding="characterset | ISO-8859-1"]???? // ?ㄤ???瀹?褰??? Jsp ??浠剁??缂????瑰?锛?????浠舵??韬???缂????瑰???
????????????????????????????????????? [isELIgnored="true | false"]???? // ??瀹?椤甸?㈡????拷??EL 琛ㄨ揪寮?锛?榛?璁ゅ?间负 false??
????????????????????? (2) include ??浠わ??ㄤ?寮??ュ?跺?? Jsp 椤甸???濡???浣跨??include ??浠ゅ??ヤ??跺?? Jsp 椤甸????d? Jsp ???″?ㄥ???杩?涓や釜 Jsp 缈昏????涓?涓? Servlet锛???浠?include ??浠ゅ??ラ??甯哥О涓洪????寮??ャ??
???????????????????????????? <%@ include file="url" %> ?朵腑濡??? URL ??璺?寰?浠?"/" 寮?澶村??琛ㄧず褰????? Web 搴??ㄣ??Jsp ??瑙???涓?寤鸿??琚?寮??ョ??椤甸?㈠??缂????? .jspf???变?????寮??ユ??灏?涓や釜 Jsp 缂?璇???涓?涓? Servlet ?ユ??缁?瀹㈡?锋?虹??锛???浠ヤ袱涓?琚?寮??ョ?? Jsp 椤甸?㈡??浠や??藉?茬????骞朵?琚?寮??ョ?? Jsp 椤甸???瑕??虹??Jsp 妯$????绱?锛?涔?灏辨?? HTML ????绛撅????? HTML ????绛惧??瀹逛?琚???缁?瀹㈡?锋?猴?????浠g??涓?浼?????
???????????????????????????????ㄦ??寮??ワ??╃??request 瀵硅薄?? getRequestDispatcher("URL").include(request,response); ?规???????锛?????Servlet 杩?琛??跺?ㄦ????灏??跺???? Servlet ???ュ?伴〉??腑锛?瑕?澶?娆″?????″?ㄨ?锋?锛???浠ユ????瑕?浣?????浠??ㄥ???涓?瑕?灏介??浣跨?ㄩ????寮??ョ???规???????寮??ユ??灏?澶?涓? Servlet ??????涓?涓? Servlet ??????缁?瀹㈡?锋?恒??
涓???Jsp 涔辩????棰?????
???????Jsp 涔辩???虹?扮??????锛???浠??ㄧ?杈? Jsp ???跺??锛??变?缂?杈??ㄤ???锛???淇?瀛??? Jsp 婧???浠舵??瀹???缂????瑰?涔?涓???锛?濡?????浠??ㄨ?颁???缂?杈? Jsp ,?d? Jsp ??婧???浠剁????瑰?涓?gb2312 淇?瀛??颁???浠?纭???涓???褰??ㄦ?疯?块?????″?ㄧ???跺??锛????″?ㄩ??杩?纭???涓?缂?杈?濂界?? Jsp ??浠剁炕璇?涓?Servlet 锛??变????″?ㄤ???涓??戒汉璁捐?$??锛???浠ョ?甯搁????ISO-8859-1 ??缂????瑰?锛??变? ISO-8859-1 ??琛ㄤ腑娌℃??瀵瑰???涓???瀛?绗????浠ヤ??芥?e父缂?璇??版??锛??跺??缂?璇????? .class ??浠朵???涔辩??锛?涔?灏卞?艰?翠???缁?瀹㈡?锋?虹???版??涔?涓??芥?e父?剧ず??
??????????瑙e?虫?规?锛??㈢?舵??浠??惧?颁?涔辩????????锛??d???浠?搴?褰??у?舵???″?ㄥ? Jsp 婧???浠剁?璇??? Servlet ?堕???ㄥ??浠ョ?璇?涓???????琛ㄣ????浠ョ?杈?婧???浠剁??缂????瑰?搴?璇ヤ????″?ㄧ?璇? Jsp ??缂????瑰??镐??淬???d???浠???浠ュ??page ??浠や腑澧??? pageEncoding="utf-8" 锛???璇????″?ㄤ互 utf-8 ????琛ㄧ??????变????扮?????″?ㄤ????ㄧ??灏?璁剧疆濂界??缂????瑰?浠ュ??搴?澶寸??褰㈠???缁?瀹㈡?锋?猴???浠ュ氨娌℃??蹇?瑕???????contentType="text/html;charset=utf-8" 杩?涓? page ??浠わ?浣???涓轰??煎?硅???????″???璋ㄦ??璧疯????ヤ???浠ャ??
????Out ??寮?瀵硅薄
???????1??out ??寮?瀵硅薄?ㄤ???瀹㈡?风???????????版????out 瀵硅薄????杩?璋???pageContext 瀵硅薄?? getOut() ?规?杩?????锛??朵??ㄥ???ㄦ?涓? ServletResponse.getWriter() ?规?杩????? PrintWriter 瀵硅薄??甯哥?镐技??
????????? 2??Jsp 椤甸??腑?? out ??寮?瀵硅薄??绫诲??涓?JspWriter锛?JspWriter ?稿?浜?涓?绉?甯??瀛????界?? PriterWriter锛?璁剧疆 Jsp 椤甸?㈢?? page ??浠ょ?? buffer 灞??у??浠ヨ??村????缂?瀛?澶у?锛????冲?抽??缂?瀛???
?????????? 3??褰??? out 涓????ヤ??版??锛??d?璇ユ?版??浠?涔??跺????浼???缁?瀹㈡?锋?虹??娴?瑙????
???????????????? (1) 璁剧疆 page ??浠ょ?? buffer 灞??у?抽??浜? out 瀵硅薄??缂?瀛????斤??d?涓??????ュ?颁? out 瀵硅薄涓?锛?out 灏辩?存?ラ??缁? printWriter 瀵硅薄??缂??插?轰腑??
???????????????? (2) out 瀵硅薄??缂??插?哄凡婊°??
?????????????????(3) ?翠釜 Jsp 椤甸?㈢?????
????????????4??out 缂??插?哄伐浣?????锛?
????????????????????? 灏??版??????out 涓?锛?骞朵????存?ュ??缁?瀹㈡?锋?猴??????ㄤ? out ??缂??插?轰腑?????凤???Servlet ?? PrintWriter 涓????版????????PrintWriter ??缂??插?轰腑锛?褰? out ??缂??插?烘弧浜?锛????? Jsp 椤甸?㈡?ц?瀹?姣??讹????″?ㄤ?灏? out 缂??插?轰腑???版??????PrintWriter ??缂??插?轰腑锛??跺???ㄥ??缁?瀹㈡?锋?恒????浠ュ????㈠??PrintWriter 涓????版??锛?????out 涓????版??锛??d???璁哄???ョ??????椤哄?锛???????缁?瀹㈡?锋?烘?讹??绘?? PrintWriter ???版??????缁?瀹㈡?锋?恒??out 瀵硅薄灏辨??瀵?PrintWriter ????涓?娆$??层????浠??ㄥ?? Jsp 椤甸?㈢???跺??灏介??浣跨??out 瀵硅薄杈??烘?版????
浜???Jsp 瀹??版??浠朵?杞铰???????
[java]? view plain copy print ?
- <%@?page?language="java"?import="java.util.*"?pageEncoding="utf-8"%><%@page?import="java.io.FileInputStream"%><%@page?import="java.io.OutputStream"%>??
- <%@page?import="java.net.URLEncoder"%><!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"><%??
- ????????String?path?=?application.getRealPath("download/?剧??.jpg");??
- ????????String?filename?=?path.substring(path.lastIndexOf("\\")?+?1);??
- ????????FileInputStream?in?=?new?FileInputStream(path);??
- ????????int?len?=?0;??
- ????????byte[]?b?=?new?byte[1024];??
- ????????OutputStream?os?=?response.getOutputStream();??
- ????????response.setHeader("content-disposition","attachment;filename="?+?URLEncoder.encode(filename,"utf-8"));??
- ????????while((len?=?in.read(b))?!=?-1){??
- ????????????os.write(b,?0?,len);??
- ????????}??
- ????????in.close();??
- ?????%> ?
????pageContext 瀵硅薄? ? ? ? ? ? ? ? ? ? ? ? ? ?
?????????????????pageContext 瀵硅薄?? Jsp ????涓?????瑕???涓?涓?瀵硅薄锛?瀹?浠h〃 Jsp 椤甸?㈢??杩?琛???澧???pageContext 涓?浠?灏?瑁?浜??跺?? 8 澶ч??寮?瀵硅薄锛?瀹???韬?杩???涓?涓???瀵硅薄锛???浠ョ?ㄦ?ヤ?瀛??版????骞朵?杩?涓?瀵硅薄杩?灏?瑁?浜? Web 寮???涓?缁?甯歌?捐?″?扮??涓?浜?甯哥?ㄦ??浣?锛?渚?濡?寮??ュ??璺宠浆?跺??璧?婧?锛?妫?绱㈠?跺????瀵硅薄涓???灞??х????
??????????? 1??pageContext 灏?瑁??跺??8澶у?硅薄????涔????ㄤ???瀹?涔???绛撅??ㄧ??瀹???杞?浠跺伐绋?椤圭???????Jsp 椤甸?㈡??涓ョ??虹?颁?琛? Java 浠g????锛?濡???瑕?浣跨??Java 浠g??锛???浠?蹇?椤讳娇?ㄨ??瀹?涔???绛炬??瀹?灏?瑁???锛??跺???ㄤ?涓? Java 绫诲?归?昏??版??杩?琛?澶???锛??d??跺?? Java 绫绘??娌℃??璇ヨ?锋????版????锛???浠?蹇?椤讳? request 杩??伙?杩??锋??寰?楹荤????????浠???浠ヤ娇??pageContext ???ヨ?峰???跺??瀵硅薄锛?涔?灏辨??浼??? pageContext 涓?涓?瀵硅薄杩??诲氨??浠ヤ???
???????????? 2??pageContext 瀵硅薄?????藉?ㄦ????浣??ㄨ???淬??pageContext ?????藉?ㄦ??涓?椤甸?㈡???稿???锛?椤甸?㈣???寤哄?? pageContext 涔?灏辫???寤猴?椤甸?㈠?抽??锛?pageContext 涔?灏遍??涔??ф????瀹???浣??ㄨ???翠????ㄥ?????椤甸?㈣???翠?????
????????????? 3??pageContext ??浣??朵?????getAttribuate(String name) ?规???涓?涓???杞斤?绗?涓?涓?褰㈠???榛?璁や?褰????? pageContext 涓?妫?绱㈡?版??锛?绗?浜?涓? getAttribuate(String name,int SCOPE?) ??浠???瀹????????㈣?峰???版????
??????????????????? pageContext ????渚?浜?缁?涓???浣???涓??????ュ?o?浠ュ??濡???瑕????烘?版??锛?蹇?椤绘??瀹?浠???????锛??板?ㄥ??浠ョ?涓???浠? pageContext 涓????烘?版?????朵腑 PAGE_SCOPE 甯搁??琛ㄧず???? pageContext ??锛???涓???褰???椤甸??page??
??????????????????? * pageContext.findAttribuate(""); 棣???浠? pageContext ??涓??ユ?撅?濡????句??帮?灏变? request ??涓??撅??句??帮?灏变? session ??涓??撅??句??板氨浠? application 涓??撅?濡???杩????句??板氨杩??? null??page??--->request--->session--->application??
??????????????????? pageContext 杩???浠ュ??杞?????????绛???浣???锛?forward??include锛?
涓???Jsp 绠?????绛?
???????Jsp ??绛句?绉颁负 Jas Action锛?Jsp ?ㄤ???绱?锛?锛?瀹??ㄤ???Jsp 椤甸??腑??渚?涓??¢?昏????斤??垮????Jsp 椤甸??腑?存?ョ??? Java 浠g??锛????? Jsp 椤甸?㈤?句互缁存?ゃ??
????????? 1??SUN ???告??渚??? Jsp 甯哥?ㄦ??绛?
??????????????? <jsp:include>
??????????????? <jsp:forward>
????????????????<jsp:param>
???????????2????灏? Jsp????涓?Jsp ??韬?灏辨??涓?涓??Servlet锛???浠ユ??浠???浠ヤ娇?ㄦ??灏? Servlet ???瑰??? Jsp ??灏??板???涓?涓??板??涓??汇??
???????????????? <servlet>
????????????????????????? <servlet-name>servletDemo</servlet-name>
??????????????????????????<jsp-file>/index.jsp</jsp-file>
?????????????????</servlet>
?????????????????<servlet-mapping>
????????????????????????????<servlet-name>servletDemo</servlet-name>
????????????????????????????<url-pattern>/xxx.jsp</url-pattern>
??????????????????<serlvet-mapping>
????Jsp ??浣? JavaBean ??绛?
???????Jsp ??????渚?浜?涓?涓??充? JavaBean ??绛惧??绱?
????????? 1??<jsp:useBean>锛??ㄤ???Jsp 椤甸??腑?ユ?炬??瀹?渚???涓?涓? JavaBean 缁?浠躲??
??????????2??<jsp:setProperty>锛??ㄤ???Jsp 椤甸??腑璁剧疆涓?涓? JavaBean 缁?浠剁??灞??с??
????????? 3??<jsp:getProperty>锛??ㄤ???Jsp 椤甸??腑?峰??涓?涓? JavaBean 缁?浠剁??灞??с??
??????????<jsp:useBean>锛??ㄦ??瀹????????村???ユ?惧?跺????绉扮?? JavaBean 瀵硅薄锛?濡???瀛??ㄥ???存?ヨ???璇ュ?硅薄??寮????濡???涓?瀛??ㄥ??瀹?渚???涓?涓??扮?? JavaBean?瀵硅薄骞跺?瀹?浠ユ??瀹?????绉板???ㄥ?版??瀹????????翠腑??
?????????? 娉ㄦ??锛??ㄧ??setProperty 涓?JavaBean 璧??肩???跺??锛?JavaBean ??绛惧??????8绉??烘???版??绫诲???????ㄧ被??杞?????跺??绫诲??涓??借???ㄨ浆????
涔???Jsp 寮???妯″?
???????Jsp ??涓ょ?寮???妯″?锛?涓?绉??? Jsp + JavaBean 妯″?锛?涓?绉????Jsp + Servlet +JavaBean 妯″???Jsp + JavaBean ????寮???涓??¢?昏?涓?澶????? Web 搴??ㄧ?搴?锛?杩?绉?妯″?涓?锛?JavaBean ?ㄤ?灏?瑁?涓??℃?版??锛?Jsp 璐?璐e????ㄦ?疯?锋????剧ず?版????Jsp + Servlet +JavaBean 锛?MVC? Model/View/Control锛?妯″?????寮???澶????? Web 搴?????ㄨ?绉?妯″?涓?锛? Servlet 璐?璐e????ㄦ?疯?锋?锛?Jsp 璐?璐f?版???剧ず锛?JavaBean 璐?璐e?瑁??版????
????????? 绠????? Jsp + JavaBean 妯″?妗?渚?
[java]? view plain copy print ?
- <%@?page?language="java"?import="java.util.*"?pageEncoding="utf-8"%>??
- ??
- <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">??
- <html>??
- ??<head>??
- ????<title>璁$????lt;/title>??
- ??</head>??
- ????
- ??<jsp:useBean?id="calc"?class="bean.Calculator"?scope="session"/>??
- ??<jsp:setProperty?property="*"?name="calc"?/>??
- ??<%??
- ????calc.operate();??
- ??%>??
- ???
- ??<body>??
- ????<hr?width="30%">??
- ????????<div?align="center">??
- ????????????璁$??缁?????锛?<jsp:getProperty?property="firstNum"?name="calc"/>??
- ???????????????????????<jsp:getProperty?property="operator"?name="calc"/>??
- ???????????????????????<jsp:getProperty?property="secondNum"?name="calc"/>=??
- ???????????????????????<jsp:getProperty?property="result"?name="calc"/>??
- ????????</div>??
- ????<hr?width="30%"><br><br>??
- ????<form?action="/Day_07_Jsp_EL/calculator.jsp"?method="post">??
- ????????<table?width="30%"?string">"1"?align="center">??
- ????????????<tr>??
- ????????????????<td?colspan="2">绠?????璁$????lt;/td>??
- ????????????</tr>??
- ????????????<tr>??
- ????????????????<td>绗?涓?涓????帮?</td>??
- ????????????????<td><input?type="text"?name="firstNum"/></td>??
- ????????????</tr>??
- ????????????<tr>??
- ????????????????<td>杩?绠?绗??</td>??
- ????????????????<td>??
- ????????????????????<select?name="operator">??
- ????????????????????????<option?value="+">+</option>??
- ????????????????????????<option?value="-">-</option>??
- ????????????????????????<option?value="*">*</option>??
- ????????????????????????<option?value="/">/</option>??
- ????????????????????</select>??
- ????????????????</td>??
- ????????????</tr>??
- ????????????<tr>??
- ????????????????<td>绗?浜?涓????帮?</td>??
- ????????????????<td><input?type="text"?name="secondNum"/></td>??
- ????????????</tr>??
- ????????????<tr>??
- ????????????????<td?colspan="2">??
- ????????????????????<input?type="submit"?value="??浜?/>??
- ????????????????</td>??
- ????????????</tr>??
- ????????</table>??
- ????</form>??
- ??</body>??
- </html> ?
????EL 琛ㄨ揪寮?
???????EL 锛?Expression Language锛???涓昏?浣?????峰???版?????ц?杩?绠????峰?? Web 寮???甯哥?ㄥ?硅薄??
????????? 1???峰???版??锛?EL 琛ㄨ揪寮?涓昏??ㄤ??挎?㈡?? Jsp 椤甸??腑??????琛ㄨ揪寮?锛?浠ヤ???绉?绫诲???? Web ??涓?妫?绱?Java 瀵硅薄???峰???版??
??????????????? (1) ?峰???????㈢???版??锛?${data}锛????哄?????㈠?抽??瀛?涓?data ???版??
????????????????????? ???″?ㄤ?灏? ${data} 缈昏??涓猴?pageContext.findAttribuate("data");
???????????????????????句??颁?浼?杩??? null锛?????杩??? ""
?????????????? ??(2) ?峰?? JavaBean 涓????版??锛?${bean.property}
??????????????? ?(3) ?峰?? JavaBean 涓?缁存?ょ???跺???? JavaBean涓????版??锛?${bean1.bean2.property}
???????????????? (4) ?峰??????涓????版??锛?${list[1].property}锛?濡??? "." ??涓??烘?版????璇?灏辨?㈡??[]
???????????????? (5) ?峰?? Map 涓????版??锛?${map.key.property}锛??????藉??涓??猴?姣?濡? key 涓烘?板??锛??d?灏卞?? ''锛?${map['key'].property}
????????????? 2???ц?杩?绠?锛??╃??EL 琛ㄨ揪寮???浠ュ??Jsp 椤甸??腑?ц?涓?浜??烘?????崇郴杩?绠????昏?杩?绠???绠??拌?绠???
?????????????????? (1) ${user==null}
????????????????????????${username=='aaa' && password='bbb'}
??????????????????????? ${1+1}
????????????????????(2) empty 杩?绠?绗??妫??ラ????????负 null ?? "绌?
??????????????????? (3) 浜???杩?绠?绗??${gender=='male'?checked:''}
??????????????3???峰?? Web 寮???甯哥?ㄥ?硅薄锛?EL 琛ㄨ揪寮?瀹?涔?浜? 11 涓???寮?瀵硅薄
??????????????????? 璇?娉?锛?${瀵硅薄??绉?
????????????????????(1)??${pageContext} ?峰????pageContext 瀵硅薄锛?瀹?涓????ㄥ??涓??????㈠?绘?撅????????ㄨ??宸卞??涔???瀵硅薄涓??撅?濡????惧?颁?灏卞???烘?ャ??
????????????????????????????${pageContext.request.contextPath} ?峰????瀵瑰???宸ョ????稿?硅矾寰?锛?搴??ㄤ? URL 涓?锛???涓烘??浠?涓?搴?璇ュ? URL ??姝诲?ㄤ唬??涓???
??????????????????? (2)??${pageScope} 寰??扮???? page ?? (pageContext) 涓?淇?瀛??版???? Map??????涔?灏辨????瀹???page ??涓??ユ?俱??
??????????????????? (3-5)??${requestScope}??${sessionScope}??${applicationScope} ??涓??㈢?? pageScope 涓??凤??芥???ㄧ?瑰??????涓?妫?绱㈡?版????
????????????????????(4)??${param} ?峰??瀛???request 涓?璇锋????扮?? Map锛?甯哥?ㄥ?ㄦ?版?????句???
????????????????????(5)??${paramValues} ?峰??瀛???request 涓?璇锋????板???稿?????肩?? String[] ?扮???
????????????????????(8)??${header} ?峰?? HTTP 璇锋?澶寸?? Map 瀵硅薄??
??????????????????? (9)??${headValues} ?峰?? HTTP 璇锋?澶村?肩?? Map 瀵硅薄
????????????????????(10)??${cookie} ?峰?????? cookie ?? Map 瀵硅薄
????????????????????(11)??${initParam} ?峰??淇?瀛????? Web 搴??ㄥ??濮??????扮?? Map 瀵硅薄
?????????????? 4??EL ?芥?帮?
?????????????????????EL 琛ㄨ揪寮?璇?娉???璁稿???浜哄??寮?????瀹?涔??芥?帮?浠ヨ???Java 绫荤???规?????EL 琛ㄨ揪寮?涓?璋??ㄧ?????芥?? Java 绫荤???????规?锛?骞朵?杩?涓??规?蹇?椤诲?ㄤ互?舵?? TLD ??浠朵腑??杩般??渚?濡??板?ㄥ??cn ??涓???涓?涓? Demo ?? 绫伙?绫讳腑??涓?涓??????规? public static String join(String s1, String s1)锛??跺????涓?涓? TLD ??杩版??浠讹???<taglib> ??绱?涓????ュ????绱? :
????????????????????????? <function>
?????????????????????????????????<name>dk</name>
????????????????????????????????? <function-class>cn.Demo</function-class>
????????????????????????????????? <function-signature>public static java.lang.String join(java.lang.String s1, java.lang.String s1)</function-signature>
??????????????????????????? </function>
??????????????????????????? <uri>/driverking</uri>
?跺????Jsp 椤甸??腑???ユ??绛惧?澹版??锛?
?<%@ taglib uri="/driverking" prefix="TLD??浠跺????缂?" %>
?跺??灏卞??浠ュ??Jsp 椤甸??腑浣跨?ㄥ??涓?dk ????绛句?锛?
${dk:join("aaa","bbb")}
??涓???EL ?芥?板?
????????????ㄩ〉?㈡?剧ず???跺????浠?甯稿父瀵瑰??绗?覆杩?琛?澶???锛?SUN ???告??渚?浜?涓?涓? EL ?芥?板??逛究??浠?????浣???
?????????????? 1??fn:toLowerCase
???????????????2??fn:toUpperCase
???????????????3??fn:trim 锛????ゅ??绗?覆??棣?灏剧┖?硷?
?????????????? 4??fn:length 锛?杩??????????扮???澶у?锛???杩???瀛?绗?覆??瀛?绗?釜?帮?
?????????????? 5??fn:split 浠ユ??瀹?瀛?绗?覆???插??绗?覆
?????????????? 6??fn:join 浠ュ??绗?覆涓哄????绗??涓?涓?瀛?绗?覆?扮?浠ュ????绗???褰㈠?杩??ヨ捣?ワ?濡???绗?浜?涓????颁负绌哄??绗?覆锛??d???灏?瀛?绗?覆?翠釜杩?璧锋?ャ??
?????????????? 7??fn:indexof 杩?????瀹?瀛?绗?覆?ㄤ?涓?瀛?绗?覆涓?棣?娆″?虹?扮??浣?缃???濡???娌℃????????杩??? -1锛?濡???绗?浜?涓????颁负绌哄??绗?覆?d?杩??? 0
?????????????? 8??fn:contains
?????????????? 9??fn:replace
?????????????? 10??fn:sunstring 锛?涓? java 涓???锛?????瀛?绗?覆涓??????垮害?ユ????锛?????浠?寮?濮??扮?????绱㈠??锋?ユ????锛?
?????????????? 11??fn:substringAfter 锛?????骞惰???涓?涓?瀛?绗?覆涓?????瀹?瀛?绗?覆绗?涓?娆″?虹?颁?????瀛?绗?覆锛?
?????????????? 9??fn:containsIgnoreCase
?????????????? 10??fn:startsWith 妫?娴?涓?涓?瀛?绗?覆????互??瀹?瀛?绗?覆寮?濮?