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Öд«µÝ²ÎÊý»á³öÏÖÂÒÂë
½â¾ö·½·¨ÈçÏ£º
Ò»¡¢Ê¹Óøü¸ÄTomcatµÄ·½·¨¡£Õâ¸ö·½·¨¼òµ¥£¬µ«ÊÇÐèÒª¸Ä¶¯µÄµØ·½ÊÇ·þÎñÆ÷Èí¼þ¼¶±ðµÄ£¬Èç¹ûÉÔ΢±ä¶¯ÏµÍ³½«ÎÞ·¨ÕýȷתÂ룬ÒÆÖ²ÐÔ²»¸ß¡£
1¡¢À´µ½tomcatĿ¼£¬ÕÒµ½confĿ¼ÏµÄserver.xmlÎʼۣ¬´ò¿ª£¬ÕÒµ½<Connector>±êÇ©£¬ÔÚ×îºóÌí¼ÓURIEncoding=’GBK’£¬Ð ......
£±.×îÖ±½Ó×î¼òµ¥µÄ£¬·½Ê½ÊÇ°ÑÎļþµØÖ·Ö±½Ó·Åµ½htmlÒ³ÃæµÄÒ»¸öÁ´½ÓÖС£ÕâÑù×öµÄȱµãÊÇ°ÑÎļþÔÚ·þÎñÆ÷ÉϵÄ·¾¶±©Â¶ÁË£¬²¢ÇÒ»¹ÎÞ·¨¶ÔÎļþÏÂÔؽøÐÐÆäËüµÄ¿ØÖÆ£¨ÈçȨÏÞ£©¡£Õâ¸ö¾Í²»Ð´Ê¾ÀýÁË¡£
£².ÔÚ·þÎñÆ÷¶Ë°ÑÎļþת»»³ÉÊä³öÁ÷£¬Ð´Èëµ½response£¬ÒÔresponse°ÑÎļþ´øµ½ä¯ÀÀÆ÷£¬ÓÉä¯ÀÀÆ÷À´ÌáʾÓû§ÊÇ·ñÔ¸Òâ±£´æÎ ......
×Ô¶¨Òå±êÇ©ÊÇÈÿª·¢ÈËÔ±´´½¨¿Í»§»¯µÄ±êÇ©,²¢ÇÒÔÚjspÎļþÖÐʹÓÃÕâЩ±êÇ©,ÕâÑù¿ÉÒÔʹjsp´úÂë¸ü¼ò½à!
Ê×ÏÈÕâÀïÏȽéÉÜ´Ó¶¨Òå±êÇ©µ½Ê¹ÓñêÇ©µÄ²½Öè:
1,´´½¨×Ô¶¨Òå±êÇ©´¦ÀíÀà,¼°Ïà¹ØÀà.class ²¢ÇÒ°ÑËûÃǶ¼·ÅÔÚWEB-INF/classesĿ¼ÏÂ
2,´´½¨TLD±êÇ©¿âÃèÊöÎļþ(.tld)Î ......
ÔÚ²»ÔÊÐíĿ¼ä¯ÀÀµÄÇé¿öÏ ä¯ÀÀÆ÷»áÏÈÕÒµ½Ê×Ò³£¨Ä¬ÈÏΪindex.html /index.jsp...£©
·ñÔò³ö´í
Òò´Ë ÈôÊ×Ò³±»¶ñÒâ¸ü¸Ä ÍøÕ¾±ÀÀ£
½â¾ö·½·¨£º
¸ü¸ÄĬÈÏÆô¶¯Ò³Ã棺$tomcat/conf/web.xml×îºóλÖÃ
<welcome-file-list>
<welcome-file>index.html</welcome-file> ......
ÔÚÍøÉÏ¿´µ½Ò»Ð©Ìû×Ó£¬×ܽáÁËһЩÇø±ð£¬¿ÉÒÔ´ÓÒÔϼ¸¸ö·½ÃæÀ´¿´£º
1.´ÓµØÖ·À¸ÏÔʾÀ´Ëµ
forwardÊÇ·þÎñÆ÷ÇëÇó×ÊÔ´,·þÎñÆ÷Ö±½Ó·ÃÎÊÄ¿±êµØÖ·µÄURL,°ÑÄǸöURLµÄÏìÓ¦ÄÚÈݶÁÈ¡¹ýÀ´,È»ºó°ÑÕâЩÄÚÈÝ
ÔÙ·¢¸øä¯ÀÀÆ÷.ä¯ÀÀÆ÷¸ù±¾²»ÖªµÀ·þÎñÆ÷·¢Ë͵ÄÄÚÈÝ´ÓÄÄÀïÀ´µÄ,ËùÒÔËüµÄµØÖ·À¸»¹ÊÇÔÀ´µÄµØÖ·.
redirectÊÇ·þÎñ¶Ë¸ù¾ÝÂß¼,·¢ËÍÒ»¸ö×´ ......