JSPÓëSevletµÄÏ໥ͨÐÅ·½Ê½(¶þ)
Servlet£º
ÔÚServletÖУ¬ÌøתÔÚdoGet»òÕßdoPost·½·¨ÖÐʵÏÖ¡£
<1>redirectʵÏÖÒ³ÃæÌøת£º
response.sendRedirect("/login.jsp");
·½·¨µÄ²ÎÊýÊÇÏà¶Ô·¾¶£¬É趨Õâ¸ö²ÎÊý¿ÉÒÔʹҳÃæÌøתµ½ÈκÎÒ³Ã棬°üÀ¨www.baidu.comµÈÍøÂçÒ³Ãæ¡£
ÌøתºóÄã¿ÉÒÔ·¢ÏÖµØÖ·À¸·¢ÉúÁ˱仯¡£
µ×²ãÔÀí£ºÊ¹ÓÃredirect·½Ê½£¬ÊµÏÖÒ³ÃæÌøתʱÓÉ¿Í»§¶ËÍê³ÉµÄ¡£¸Ã·½·¨ÊµÏÖµÄʱºò£¬ÊÇͨ¹ý¸Ä±äHTTPÐÒéµÄHeader²¿·Ö£¬¶Ôä¯ÀÀÆ÷Ï´ïÌøתÃüÁî¡£¸Ã·½·¨¿ÉÒÔ½ÓÊܾø¶Ô·¾¶»òÕßÏà¶Ô·¾¶£¬Èç¹ûÊÇÏà¶Ô·¾¶£¬»á½âÎö³É¾ø¶Ô·¾¶È»ºó´«¸ø¿Í»§¶Ë¡£
´«ÖµÒªÇó£ºÖ»ÄÜÖØдURL£¬»òÕßÓÃSession´«Öµ£¬¶ø²»ÄÜÓÃrequest.setAttribute()´«Öµ¡£
<2>forwardʵÏÖÒ³ÃæÌøת£º
RequestDispatcher dipatcher=request.getRequestDispatcher("/login.jsp");
dispatcher.forward(request,response);
Ö»ÄÜÌøתµ½±¾webÓ¦ÓÃÖеÄÒ³Ãæ¡£µØÖ·À¸²»·¢Éú±ä»¯
µ×²ãÔÀí£ºforwardÊÇÔÚ·þÎñÆ÷¶Ë×öÒ³Ã涨Ïò£¬È»ºóÔÙÏò¿Í»§¶Ë·¢ËÍÊý¾Ý£º·þÎñÆ÷¶ËÏȽ«Êý¾ÝÊä³öµ½»º³åÇø£¬µ±£¨1£©À´×Ô¿Í»§¶ËµÄËùÓÐrequest´¦ÀíÍ꣬²¢°ÑËùÓÐÊý¾ÝÊä³öµ½»º³åÇø£¨2£©»º³åÇøÂú£¨3£©ÔÚ³ÌÐòÖе÷Óûº³åÇø·½·¨out.flush()»òÕßresponse.flushbuffer()£¬ÈýÕßÂú×ãÆäһʱ£¬web container²Å½«»º³åÇø·³ÈËÄÚÈÝ´«Ë͸ø¿Í»§¶Ë¡£
´«ÖµÒªÇó£ºÖØдURL£¬»òÕßÓÃSession´«Öµ£¬»òÕßÓÃrequest.setAttribute()´«Öµ¡£
JSP£º
<1>response.sendRedirect()ºÍserlvletµÄresponse.sendRedirect()Ò»Ñù
´ËÓï¾äÇ°²¿ÔÊÐíʹÓÃout.flush£¬·ñÔò»áÅ׳öÒì³£
Èç¹ûÌøתµ½²»Í¬Ö÷»ú£¬Ìøתºó£¬´ËÓï¾äºóÃæµÄÓï¾ä¼ÌÐøÖ´ÐУ¬¾ÍÏñÊÇпªÁËÒ»¸öỊ̈߳¬µ«ÊǴ˺ó¶ÔresponseµÄ²Ù×÷ÎÞЧ
Èç¹ûÌøתµ½ÏàͬµÄÖ÷»ú£¬´ËÓï¾äºóÃæµÄÓï¾äÖ´ÐÐÍê±ÏÖ®ºó²Å·¢ÉúÌøת
ÌøתºóµØÖ·À¸·¢Éú±ä»¯
<2>response.setHeader("Location","")
´ËÓï¾äÇ°²»ÔÊÐíÓÐout.flush()£¬Èç¹ûÓУ¬²»·¢ÉúÌøת
´ËÓï¾äºóÃæµÄÓï¾äÖ´ÐÐÍê³Éºó²Å»áÌøת
Ìøתºóä¯ÀÀÆ÷µØÖ·À¸±ä»¯
<3><jsp:forward page="" />
&nb
Ïà¹ØÎĵµ£º
ѧϰJSPÖ÷ҪѧϰËûµÄ9´ó¶ÔÏó(request, response, pageContext, session, application, out, config, page, exception ),ÕâЩ¶ÔÏó¶¼ÊǾ²Ì¬¶ÔÏ󣬲»Óö¨Òå¾Í¿ÉÒÔÖ±½ÓʹÓ㬰ÑËûÃǶ¼Á˽âÇå³þ²¢»áÔËÓ㬾ͿÉÒÔÔÚ¼òÀúÉÏÌíÉÏÒ»¸öÊìϤ¼¼ÄÜ:JSP
JspÄÚÖöÔÏó ¹¦ÄÜ Ö÷Òª·½·¨
out Ïò¿Í»§¶ËÊä³öÊý¾Ý print() println() flush() ......
Ò») °²×°JDK(jdk-1_5_0-windows-i586.exe)£¬Ä¬ÈÏ°²×°£»
(¶þ) °²×°Tomcat(tomcat5.5-installer.exe)£¬Ä¬ÈÏ°²×°£»
* ˳Ðò²»¿ÉÒԵߵ¹ *
(Èý) ²âÊÔ°²×°½á¹û
1. ´ò¿ªä¯ÀÀÆ÷ÊäÈëhttp://localhost:8080£¬Èç¹û³É¹¦£¬Ôò»á¿´µ½»¶ÓÒ³Ãæ¡£´Ëʱ·ÃÎʵÄ·¾¶Îª$tomcat/webapps/root/
(ËÄ) ½¨Á¢ÎÒµÄÕ¾µ ......
Jsp±àÂë¹æ·¶
1.1 Îļþºó׺(File Suffixes)
ÎļþÀà±ð ¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡Îļþºó׺
--------------------------------------
JavaÔ´Îļþ¡¡¡¡¡¡¡¡¡¡¡¡¡¡.java
Java×Ö½ÚÂëÎļþ¡¡¡¡¡¡¡¡¡¡.class
¶¯Ì¬Ò³Ãæ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡.jsp
¾²Ì¬Ò³Ãæ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡.html
½Å±¾Îļþ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡.js
1.2 ³£ÓÃÎļþÃû(Common ......
JSPÖеÄCOOKIE²Ù×÷
Cookie¸ÅÄî:
CookieµÄ¸ñʽʵ¼ÊÉÏÊÇÒ»¶Î´¿Îı¾ÐÅÏ¢, ÓÉ·þÎñÆ÷Ëæ×ÅÍøÒ³Ò»Æð·¢Ë͵½¿Í»§¶Ë, ²¢±£´æÔÚ¿Í»§¶ËÓ²ÅÌÖÐÖ¸¶¨µÄĿ¼µÄ. ´ó¼Ò¶¼´«ËµCookie»áÔì³ÉÑÏÖصݲȫÍþвʲôµÄ, Æäʵ²»ÊÇÕâô»ØÊÂÇé. ·þÎñÆ÷¶ÁÈ¡CookieµÄʱºò, Ö»Äܹ»¶ÁÈ¡µ½Õâ¸ö·þÎñ ......
Ç°Ì᣺¼ÙÉèÄãµÄ Http µØַΪ http://192.168.0.1/ ÄãµÄ web Ó¦ÓÃΪ webapp £¬ÄÇôÄãµÄ web Ó¦Óà URL Ϊ http://192.168.0.1/webapp/
[ÎÊÌâ1]
[ÃèÊö]µ±ÔÚ jsp ÖÐÒýÈë css ʱ£¬Èç¹ûÆäÏà¶Ô·¾¶Ïà¶ÔÓÚµ±Ç° jsp ÎļþµÄ£¬¶øÔÚÒ»¸öºÍÕâ¸ö jsp µÄ·¾¶²»Ò»ÑùµÄ servlet ÖÐ forwarder Õâ¸ö jsp ʱ£¬¾Í»á·¢ÏÖÕâ¸ö css Ñùʽ¸ù±¾Ã»ÓÐÆ ......