JSP生命周期详细信息
YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
æ们å¨å¼å项ç®çæ¶åä¸å®è¦ç解ä»ä»¬çè§åï¼å ¶å®JSPççå½å¨ææ¯ä»å建å°éæ¯çè¿ç¨ï¼ä¸é¢ç±ç«ææ¯é¢éå°ç½ç»å¤§å®¶ä»ç»JSPçå½å¨æ详ç»ä¿¡æ¯ï¼éè¦çæåå¯ä»¥åèä¸é¢çä»ç»ã
jsp çå½å¨æ
ç解JSPåºå±åè½çå ³é®å°±æ¯å»ç解å®ä»¬æéµå®ççå½å¨æã
JSPçå½å¨æå°±æ¯ä»å建å°éæ¯çæ´ä¸ªè¿ç¨ï¼ç±»ä¼¼äºservletçå½å¨æï¼åºå«å¨äºJSPçå½å¨æè¿å æ¬å°JSPæ件ç¼è¯æservletã
以ä¸æ¯JSPçå½å¨æä¸æèµ°è¿çå 个é¶æ®µï¼
- ç¼è¯é¶æ®µï¼servlet容å¨ç¼è¯servletæºæ件ï¼çæservletç±»
- åå§åé¶æ®µï¼å è½½ä¸JSP对åºçservletç±»ï¼åå»ºå ¶å®ä¾ï¼å¹¶è°ç¨å®çåå§åæ¹æ³
- æ§è¡é¶æ®µï¼è°ç¨ä¸JSP对åºçservletå®ä¾çæå¡æ¹æ³
- éæ¯é¶æ®µï¼è°ç¨ä¸JSP对åºçservletå®ä¾çéæ¯æ¹æ³ï¼ç¶åéæ¯servletå®ä¾
å¾ææ¾ï¼JSPçå½å¨æçå个主è¦é¶æ®µåservletçå½å¨æé常ç¸ä¼¼ï¼ä¸é¢ç»åºå¾ç¤ºï¼
jsp çå½å¨æ
Â
JSPç¼è¯
å½æµè§å¨è¯·æ±JSP页é¢æ¶ï¼JSPå¼æä¼é¦å å»æ£æ¥æ¯å¦éè¦ç¼è¯è¿ä¸ªæ件ãå¦æè¿ä¸ªæ件没æ被ç¼è¯è¿ï¼æè å¨ä¸æ¬¡ç¼è¯å被æ´æ¹è¿ï¼åç¼è¯è¿ä¸ªJSPæ件ã
ç¼è¯çè¿ç¨å æ¬ä¸ä¸ªæ¥éª¤ï¼
- 解æJSPæ件ã
- å°JSPæ件转为servletã
- ç¼è¯servletã
JSPåå§å
容å¨è½½å ¥JSPæ件åï¼å®ä¼å¨ä¸ºè¯·æ±æä¾ä»»ä½æå¡åè°ç¨jspInit()æ¹æ³ãå¦ææ¨éè¦æ§è¡èªå®ä¹çJSPåå§åä»»å¡ï¼å¤åjspInit()æ¹æ³å°±è¡äºï¼å°±åä¸é¢è¿æ ·ï¼
public void jspInit(){ // åå§å代ç }
ä¸è¬æ¥è®²ç¨åºåªåå§åä¸æ¬¡ï¼servletä¹æ¯å¦æ¤ãé常æ åµä¸æ¨å¯ä»¥å¨jspInit()æ¹æ³ä¸åå§åæ°æ®åºè¿æ¥ãæå¼æ件åå建æ¥è¯¢è¡¨ã
 JSPæ§è¡
è¿ä¸é¶æ®µæè¿°äºJSPçå½å¨æä¸ä¸åä¸è¯·æ±ç¸å ³ç交äºè¡ä¸ºï¼ç´å°è¢«éæ¯ã
å½JSPç½é¡µå®æåå§ååï¼JSPå¼æå°ä¼è°ç¨_jspService()æ¹æ³ã
_jspService()æ¹æ³éè¦ä¸ä¸ªHttpServletRequest对象åä¸ä¸ªHttpServletResponse对象ä½ä¸ºå®çåæ°ï¼å°±åä¸é¢è¿æ ·ï¼
void _jspService(HttpServletRequest request, HttpServletResponse response) { // æå¡ç«¯å¤ç代ç }
_jspService()æ¹æ³å¨æ¯ä¸ªrequestä¸è¢«è°ç¨ä¸æ¬¡å¹¶ä¸è´è´£äº§çä¸ä¹ç¸å¯¹åºçresponseï¼å¹¶ä¸å®è¿è´è´£äº§çææ7个HTTPæ¹æ³çååºï¼æ¯å¦GETãPOSTãDELETEççãÂ
JSPæ¸ ç
JSPçå½å¨æçéæ¯é¶æ®µæè¿°äºå½ä¸ä¸ªJSPç½é¡µä»å®¹å¨ä¸è¢«ç§»é¤æ¶æåççä¸åã
jspDestroy()æ¹æ³å¨JSPä¸çä»·äºservletä¸çéæ¯æ¹æ³ãå½æ¨éè¦æ§è¡ä»»ä½æ¸ çå·¥ä½æ¶å¤åjspDestroy()æ¹æ³ï¼æ¯å¦éæ¾æ°æ®åºè¿æ¥æè å ³éæ件夹ççã
jspDestroy()æ¹æ³çæ ¼å¼å¦ä¸ï¼
public void jspDestroy() { // æ¸ ç代ç }
å®ä¾
JSPçå½å¨æ代ç å®ä¾å¦ä¸æ示ï¼
life.jsp
ã以ä¸å°±æ¯ç±ç«ææ¯é¢éå°ç¼ç»å¤§å®¶ä»ç»çJSPçå½å¨æ详ç»ä¿¡æ¯ï¼å¸æ大家é½è½é å项ç®è¿è¡å¼åï¼è®©å®åå¾è¶æ¥è¶å®ç¾ã
上一篇:JSP过滤器解决中文乱码问题
下一篇:添加JSP验证码实现登录功能