jsp»ù´¡Ëٳɾ«»ª½²½â
ServletÈý¸öÒªËØ:
1.±ØÐë¼Ì³Ð×ÔHttpServlet
2.±ØÐëʵÏÖdoGet()»òÕßdoPost()
3.±ØÐëÔÚweb.xmlÖÐÅäÖÃServlet
<servlet>
<servlet-name> </servlet-name>
<servlet-class> </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> </servlet-name>
<url-pattern> </url-pattern>
</servelt-mapping>
HttpServeltRrequest:ÇëÇó¶ÔÏó
getParameter():»ñµÃ±íµ¥ÔªËصÄÖµ
getAttribute():»ñµÃrequest·¶Î§ÖеÄÊôÐÔÖµ
setAttribute():ÉèÖÃreqeust·¶Î§ÖеÄÊôÐÔÖµ
setCharacterEncoding():ÉèÖÃ×Ö·û±àÂë
HttpSerletResponse:ÏàÓ¦¶ÔÏó
sendRedirect():ÍⲿÌøת
getWriter():»ñµÃÊä³öÁ÷¶ÔÏó
setContentType("text/html; charset=utf-8"):ÉèÖÃÏàÓ¦ÄÚÈݸñʽºÍ±àÂë
ËÄÖֻỰ¸ú×Ù·½Ê½:
1.Session
HttpSession session = request.getSession();
session.setAttribute("name", "zhangsan");
session.setAttribute("pwd", "aaa");
String name = (String) session.getAttribute("name");
2.cookie:
//´´½¨Cookie
Cookie cookie = new Cookie("name", "zhangsan");
//ÉèÖÃCookieµÄ³¬Ê±Ê±¼ä
cookie.setMaxAge(24 * 60 * 60 *60);
//°ÑCookie·¢Ë͵½¿Í»§¶Ë
response.addCookie(cookie);
//µÃµ½¿Í»§¶Ë·¢Ë͵ÄCookie
Cookie [] cookies = request.getCookies();
for(int i=0; i <cookies.length; i++) {
Cookie temp = cookies;
String key = temp.getName();
String value = temp.getValue();
}
3.Òþ²Ø±íµ¥Óò
<input type="hidden" name="name" value="zhangsan" />
request.getParameter("name");
4.UrlÖØд
ÎʺŴ«²Î
LoginServlet?username=zhangsan&pwd=123
String name = request.getParameter("username");
String pwd =request.getPareameter("pwd");
ÄÚ²¿Ìøת:
LoginServlet
request.getRequestDispatcher("index.jsp").forward(request, resposne);
ÍⲿÌøת:
response.sendRedirect("index.jsp");
ÄÚ²¿ÌøתÊÇÒ»´ÎÇëÇóºÍÒ»´ÎÏìÓ¦
ÍⲿÌøתÊÇÁ½´ÎÇëÇóºÍÁ½´ÎÏìÓ¦
ServletContext:ServletÉÏÏÂÎĶÔÏó
ËüÊÇÒ»¸ö¹«¹²ÇøÓò,¿ÉÒÔ±»ËùÓеĿͻ§¶Ë¹²Ïí
setAttribute():Ïò¹«¹²ÇøÓòÀï·ÅÈëÊý¾Ý
getAttribute():´Ó¹«¹²ÇøÓòÀïÈ¡
Ïà¹ØÎĵµ£º
¼¸ºõËùÓеÄWeb¿ª·¢ÓïÑÔ¶¼Ö§³ÖSession¹¦ÄÜ£¬ServletÒ²²»ÀýÍâ¡£ Servlet/JSPÖеÄSession¹¦ÄÜÊÇͨ¹ý×÷ÓÃÓò(scope)Õâ¸ö¸ÅÄîÀ´ÊµÏֵġ£
×÷ÓÃÓò·ÖΪËÄÖÖ£¬·Ö±ðΪ£º
page
ÔÚµ±Ç°Ò³ÃæÓÐЧ(½öÓÃÓÚJSPÖÐ)
request
ÔÚµ±Ç°ÇëÇóÖÐÓÐЧ
session
ÔÚµ±Ç°»á»°ÖÐÓÐЧ
application
ÔÚËùÓÐÓ¦ÓóÌÐòÖÐÓÐЧ
ÊDz»ÊÇ¿´²»Ì«Ã÷°×£¿pageÒòΪ½ ......
±êÇ©¿âTaglib
±êÇ©±»¶¨ÒåºÍ·Ö²¼ÔÚÒ»¸ö³ÆΪ±êÇ©¿âµÄ½á¹¹ÖУ¬Ò»¸ö±êÇ©¿âÊÇÓÉÔªÐÅÏ¢ºÍÀà×é³ÉµÄ¼¯ºÏ£º
1.±êÇ©´¦ÀíÆ÷£ºÊµÏÖ¶¨ÖƱêÇ©¹¦ÄܵÄJavaÀà¡£
2.±êÇ©¸½¼ÓÐÅÏ¢£¨TEI£©£ºÏòJSPÈÝÆ÷Ìṩ±ß¼ÒÔÈ·ÈϱêÇ©ÊôÐԺʹ´½¨±äÁ¿µÄÀà¡£
3.±êÇ©¿âÃèÊöÆ÷£¨TLD£©£ºÃèÊöµ¥¸ö±êÇ©ºÍÕû¸ö±êÇ©¿âÊôÐÔµÄXMLÎĵµ¡£
±êÇ©´¦ÀíÆ÷ºÍ±êÇ©¸½¼ÓÐÅÏ¢Ðè ......
Ò»£¬´¿´âµÄjspÒ³ÃæÖÐÎÄÂÒÂë
ÔÒò£º¶Ôjsp´úÂëµÄ±àд£¬Ä¬ÈϵÄ×Ö·û¼¯Ê“ISO-8859-1”£¬Èç¹û´úÂëÖдæÔÚÖÐÎÄ£¬Ôò»á³öÏÖÂÒÂ룡
½â¾ö°ì·¨£ºÔÚpageÖмÓÉÏcontentType="text/html;charset=gb2312"£¬²ÉÓùú±êÀ´·ÒëÒ³ÃæÖеĴúÂ룡
¶þ£¬post·½Ê½Ìá½»±íµ¥³öÏÖÂÒÂë
ÔÒò£º ......
¡¡¡¡ÏµÍ³»·¾³£ºLinux 5.0 AS 64λ
¡¡¡¡²½Ö裺
¡¡¡¡1¡¢ÏÂÔØapache-tomcat-5.5.23.tarºÍjdk-1_5_0_12-linux-i586.bin²¢´æ·ÅÔÚ/usr/localÎļþ¼ÐÏ£»
¡¡¡¡2¡¢°²×°jdk
¡¡¡¡[root@localhost local]#chmod 775 jdk-1_5_0_12-linux-i586.bin '·Ç±ØÐ룬ҪÊÇÖ±½ÓÔËÐÐʱÌáʾȨÏÞ²»¹»Ê±¸Ä±äȨÏÞ£»
¡¡¡¡[root@localhost local]#./jd ......