Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JSPÓëServletµÄÏ໥ͨÐÅ·½Ê½(Ò»)

     JSPÓëServletÖ®¼äµÄ»á»°¸ú×Ù·½Ê½Óжà¸ö£¬×¢¶¨ËûÃǵÄͨÐÅ·½Ê½ÓжàÖÖ¡£
    ÏÂÃæÏÈÀ´¿´¿´4ÖлỰ¸ú×Ù·½Ê½£º
     Ò»£ºSession
     ´«ËͶˣº
      HttpSession session=request.getSession();
session.setAttribute("username","albert");
session.setAttribute("password","albert");
 
     ½ÓÊնˣº
     String username=(String)session.getAtribute("username");
String password=(String)session.getAtribute("password");
     ¶þ£ºcookie
    
     Cookie cookie=new Cookie("username","albert");
cookie.setMaxAge(24*60*60*60);
//·¢ËÍcookieµ½¿Í»§¶Ë
response.addCookie(cookie);
    
     Cookie[] cookies=request.getCookies();
for(int i=0;i<cookies.length;i++){
Cookie temp=cookie[i];
String key=temp.getName();
String value=temp.getValue();
}
     Èý£ºÒþ²Ø±íµ¥Óò
     <input type="hidden" name="username" value="albert"/>
request.getParameter("username");
     ËÄ£ºURLÖØд
     ¿Í»§¶ËHTML£º
      <form name="login" action="/LoginServlet?username=albert&password=albert">
     ·þÎñÆ÷¶ËServlet:
     String username=request.getParameter("username");
String password=request.getParameter("password");


Ïà¹ØÎĵµ£º

½â¾öJspÒ³ÃæURLÖд«µÝ²ÎÊýÂÒÂëµÄ·½·¨

JspÒ³ÃæÔÚURLÖд«µÝ²ÎÊý»á³öÏÖÂÒÂë
½â¾ö·½·¨ÈçÏ£º
Ò»¡¢Ê¹Óøü¸ÄTomcatµÄ·½·¨¡£Õâ¸ö·½·¨¼òµ¥£¬µ«ÊÇÐèÒª¸Ä¶¯µÄµØ·½ÊÇ·þÎñÆ÷Èí¼þ¼¶±ðµÄ£¬Èç¹ûÉÔ΢±ä¶¯ÏµÍ³½«ÎÞ·¨ÕýȷתÂ룬ÒÆÖ²ÐÔ²»¸ß¡£
1¡¢À´µ½tomcatĿ¼£¬ÕÒµ½confĿ¼ÏµÄserver.xmlÎʼۣ¬´ò¿ª£¬ÕÒµ½<Connector>±êÇ©£¬ÔÚ×îºóÌí¼ÓURIEncoding=’GBK’£¬Ð ......

ÓÃJspÀ´ÊµÏÖÎļþÏÂÔع¦Äܵļ¸ÖÖ·½Ê½

 
£±.×îÖ±½Ó×î¼òµ¥µÄ£¬·½Ê½ÊÇ°ÑÎļþµØÖ·Ö±½Ó·Åµ½htmlÒ³ÃæµÄÒ»¸öÁ´½ÓÖС£ÕâÑù×öµÄȱµãÊÇ°ÑÎļþÔÚ·þÎñÆ÷ÉϵÄ·¾¶±©Â¶ÁË£¬²¢ÇÒ»¹ÎÞ·¨¶ÔÎļþÏÂÔؽøÐÐÆäËüµÄ¿ØÖÆ£¨ÈçȨÏÞ£©¡£Õâ¸ö¾Í²»Ð´Ê¾ÀýÁË¡£
 
£².ÔÚ·þÎñÆ÷¶Ë°ÑÎļþת»»³ÉÊä³öÁ÷£¬Ð´Èëµ½response£¬ÒÔresponse°ÑÎļþ´øµ½ä¯ÀÀÆ÷£¬ÓÉä¯ÀÀÆ÷À´ÌáʾÓû§ÊÇ·ñÔ¸Òâ±£´æÎ ......

jspÖÐ×Ô¶¨Òå±êÇ©×ܽá(Ò»)_´«Í³±êǩƪ

×Ô¶¨Òå±êÇ©ÊÇÈÿª·¢ÈËÔ±´´½¨¿Í»§»¯µÄ±êÇ©,²¢ÇÒÔÚjspÎļþÖÐʹÓÃÕâЩ±êÇ©,ÕâÑù¿ÉÒÔʹjsp´úÂë¸ü¼ò½à!
 Ê×ÏÈÕâÀïÏȽéÉÜ´Ó¶¨Òå±êÇ©µ½Ê¹ÓñêÇ©µÄ²½Öè:
     1,´´½¨×Ô¶¨Òå±êÇ©´¦ÀíÀà,¼°Ïà¹ØÀà.class ²¢ÇÒ°ÑËûÃǶ¼·ÅÔÚWEB-INF/classesĿ¼ÏÂ
     2,´´½¨TLD±êÇ©¿âÃèÊöÎļþ(.tld)Î ......

¹ØÓÚÍøÕ¾Ê×Ò³Ãû³Æ°²È«ÐÔÎÊÌâ JSP ÔÊÐíĿ¼ä¯ÀÀ

ÔÚ²»ÔÊÐíĿ¼ä¯ÀÀµÄÇé¿öÏ     ä¯ÀÀÆ÷»áÏÈÕÒµ½Ê×Ò³£¨Ä¬ÈÏΪindex.html  /index.jsp...£©
·ñÔò³ö´í
Òò´Ë ÈôÊ×Ò³±»¶ñÒâ¸ü¸Ä   ÍøÕ¾±ÀÀ£
½â¾ö·½·¨£º
¸ü¸ÄĬÈÏÆô¶¯Ò³Ã棺$tomcat/conf/web.xml×îºóλÖÃ
<welcome-file-list>
<welcome-file>index.html</welcome-file> ......

jsp:forward±êÇ©ºÍresponse.sendRedirect()·½·¨µÄÇø±ð

ÔÚÍøÉÏ¿´µ½Ò»Ð©Ìû×Ó£¬×ܽáÁËһЩÇø±ð£¬¿ÉÒÔ´ÓÒÔϼ¸¸ö·½ÃæÀ´¿´£º
1.´ÓµØÖ·À¸ÏÔʾÀ´Ëµ
forwardÊÇ·þÎñÆ÷ÇëÇó×ÊÔ´,·þÎñÆ÷Ö±½Ó·ÃÎÊÄ¿±êµØÖ·µÄURL,°ÑÄǸöURLµÄÏìÓ¦ÄÚÈݶÁÈ¡¹ýÀ´,È»ºó°ÑÕâЩÄÚÈÝ
ÔÙ·¢¸øä¯ÀÀÆ÷.ä¯ÀÀÆ÷¸ù±¾²»ÖªµÀ·þÎñÆ÷·¢Ë͵ÄÄÚÈÝ´ÓÄÄÀïÀ´µÄ,ËùÒÔËüµÄµØÖ·À¸»¹ÊÇÔ­À´µÄµØÖ·.
redirectÊÇ·þÎñ¶Ë¸ù¾ÝÂß¼­,·¢ËÍÒ»¸ö×´ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ