Servlets/JSP¿ª·¢¼¼ÊõÎÊ´ð
ΪʲôGenericServletÔÚinit(ServletConfig config)»ù´¡ÉÏÔö¼ÓÁËÒ»¸öinit()·½·¨£¿
init()·½·¨±»GenericServlet.init(ServletConfig config)·½·¨µ÷Óá£
init()·½·¨·½±ãÁË¿ª·¢ÈËÔ±¶¨ÖÆServletµÄ³õʼ»¯£¬¶øÎÞÐëȥά»¤ServletConfig¶ÔÏóµÄ´æ´¢¹¤×÷¡£
ÖØдGenericServlet.init(ServletConfig config)±ØÐëÒªÏÔʾµÄµ÷ÓÃsuper.init(config)·½·¨¡£
ServletContext.getContect(java.lang.String uripath)µÄ×÷ÓÃÊÇʲô£¿
·µ»ØͬһServerÖÐÖ¸¶¨µÄpath¶ÔÓ¦µÄServletContext¶ÔÏó,ͨ¹ý¸Ã¶ÔÏó¿ÉÒÔʵÏÖÓëServerÖеÄÆäËûContext´ò½»µÀ¡£
uripath±ØÐëÊÇÒÔ"/"¿ªÊ¼£¨¸Ã·¾¶µÄº¬ÒåÊÇÏà¶ÔÓÚÕû¸öServletÎĵµµÄ¸ù·¾¶£¬¶ø²»Êǵ±Ç°ServletContextµÄ¸ù·¾¶£©¡£
ServletÉúÃüÖÜÆÚÊÇʲô£¿
Ò»°ãµÄServlet(GenericServlet,¼´ÓëÐÒéÎ޹صÄServlet)µÄÉúÃüÖÜÆÚ£ºinit() --> GenericServlet.service(ServletRequest req, ServletResponse res) --> destroy.
HttpServletµÄÉúÃüÖÜÆÚ: init() --> GenericServlet.service(ServletRequest req, ServletResponse res)---> service(HttpServletRequest req, HttpServletResponse resp) --> doXXXX()-->destroy.
ÓÐûÓбØÒªÖØдGenericServlet.service()·½·¨£¿
¶ÔÓÚHttpServletÀ´ËµÃ»ÓбØÒª¡£Ö»ÐèÒªÖØдËüµÄdoXXXX()·½·¨¾Í¿ÉÒÔÁË¡£HttpServletÖÐservice()·½·¨»á×Ô¶¯µÄ¸ù¾ÝÓû§ÇëÇóÀàÐÍ°ÑÇëÇóת·¢¸øÏàÓ¦µÄdoXXXX()·½·¨£¨ÀýÈçdoGet()·½·¨£©¡£
ServletRequest.getReader()ºÍServletRequest.getInputStream()ÈçºÎʹÓã¿
×¢ÒâÁ½¸ö·½·¨²»ÄÜͬʱʹÓá£
ServletRequest.getRealPath(String path)·½·¨ÒѾ²»ÍƼöʹÓá£
ÇëʹÓÃServletContext.getRealPath(String path)·½·¨¡£
ServletResponseȱʡµÄ×Ö·û¼¯(charset)ÊÇʲô?
ServletResponseȱʡµÄ×Ö·û¼¯(charset)ÊÇISO-8859-1,¿ÉÒÔͨ¹ýsetContentType(java.lang.String)·½·¨¸Ä±äеÄ×Ö·û¼¯¡£
ÀýÈ磺setContentType("text/html; charset=Shift_JIS").
¹ØÓÚ×Ö·û¼¯ÐÅÏ¢£¬¿ÉÒÔä¯ÀÀRFC 2045
HttpServletRequest.getRequestURI()ºÍHttpServletRequest.getRequestURL()Çø±ðÊÇʲô?
request.getRequestURI() ·µ»ØÖµÀàËÆ£º/xuejava/requestdemo.jsp
request.getRequestURL() ·µ»ØÖµÀàËÆ£ºhttp://localhost:8080/xuejava/requestdemo.jsp
HttpServletRequest.encodeURL()ºÍHttpServletRequest.encodeRedirectURL(()Çø±ðÊÇʲô?ΪʲôҪÓÐÁ½¸ö²»Í¬µÄ·½·¨
Ïà¹ØÎĵµ£º
JSP/Servlet µÄ¹Øϵ
JSP £¦Servlet ÊôÓÚjava web ²ãµÄ¼¼Êõ£¬×÷Óö¼ÊÇÓÃÀ´ÊµÏÖ¶¯Ì¬ÍøÒ³¡£JSP Ö÷ÒªÃæÏòµÄÊÇÍøÒ³Éè¼ÆÈËÔ±£¬Servlet Ö÷ÒªÃæÏòµÄÊdzÌÐòÉè¼ÆÈËÔ±¡£ÎÞÂÛÄã²ÉÓÃÁ½ÕßÖÐÄÄÒ»ÖÖµ¥Ò»µÄ¼¼Êõ£¬Ä㶼¿ÉÒÔ½â¾öËùÓж¯Ì¬ÍøÒ³³ÊÏÖµÄÎÊÌâ¡£´ÓÔËÐз½Ê½ÉϽ²£¬JSP ÊÂʵÉÏÐèҪתÒëΪServlet ²ÅÄÜÔËÐУ¬ËùÒÔ£¬ÓÐÒ»ÖÖ˵·¨ËµËüÃÇÊÇ"һà ......
1. RequestDispatcher.forward()
ÊÇÔÚ·þÎñÆ÷¶ËÆð×÷ÓÃ,µ±Ê¹ÓÃforward()ʱ,Servlet engine´«µÝHTTPÇëÇó´Óµ±Ç°µÄServlet or JSPµ½ÁíÍâÒ»¸öServlet,JSP »òÆÕͨHTMLÎļþ,Ò²¼´ÄãµÄformÌá½»ÖÁa.jsp,ÔÚa.jspÓõ½ÁËforward()Öض¨ÏòÖÁb.jsp,´ËʱformÌá½»µÄËùÓÐÐÅÏ¢ÔÚ b.jsp¶¼¿ÉÒÔ»ñµÃ,²ÎÊý×Ô¶¯´«µÝ. µ«forward()ÎÞ·¨Öض¨ÏòÖÁÓÐframeµ ......
°ÑÄÇЩÏÞÖÆ·ÃÎʵÄ×ÊÔ´£¨±ÈÈç˵jspÔ´´úÂ룩·Åµ½WebÓ¦ÓõÄWEB-INFĿ¼Ï£¬¶ÔÓÚ/web-INF/¼°Æä×ÓĿ¼£¬²»ÔÊÐíÖ±½ÓµÄ¹«¹²·ÃÎÊ£¬ËùÒԾͿÉÒÔÆðµ½±£»¤ÕâЩ´úÂëδ¾ÊÚȨµÄ·ÃÎʺͿúÊÓ£¬¸üºÃµÄ±£»¤ÁËÔ´´úÂë¡£
ͨ³£JSP¿ª·¢ÈËÔ±»á°ÑËûÃǵÄÒ³ÃæÎļþ´æ·ÅÔÚWebÓ¦ÓÃÏàÓ¦µÄ×ÓĿ¼Ï¡£ÕâÖÖ·½·¨µÄÎÊÌâÊÇ ......
Ò» MVCÉè¼ÆģʽµÄ¸ÅÄî
MVC±¾À´ÊÇ´æÔÚÓÚDesktop³ÌÐòÖеģ¬MÊÇÖ¸Êý¾ÝÄ£ÐÍ£¬VÊÇÖ¸Óû§½çÃ棬CÔòÊÇ¿ØÖÆÆ÷¡£Ê¹ÓÃMVCµÄÄ¿µÄÊǽ«MºÍVµÄʵÏÖ´úÂë·ÖÀ룬´Ó¶øʹͬһ¸ö³ÌÐò¿ÉÒÔʹÓò»Í¬µÄ±íÏÖÐÎʽ¡£±ÈÈçÒ»Åúͳ¼ÆÊý¾ÝÄã¿ÉÒÔ·Ö±ðÓÃÖù״ͼ¡¢±ýͼÀ´±íʾ¡£C´æÔÚµÄÄ¿µÄÔòÊÇÈ·±£MºÍVµÄͬ²½£¬Ò»µ©M¸Ä±ä£¬VÓ¦¸Ãͬ²½¸üС£& ......
ÎÒÃǶ¼ÖªµÀÔÚjspÖÐincludeÓÐÁ½ÖÖÐÎʽ,·Ö±ðÊÇ
< %@ include file=” ”% >
< jsp:include page=” ” flush=”true”/ >
Ç°ÕßÊÇÖ¸ÁîÔªËØ¡¢ºóÕßÊÇÐÐΪԪËØ¡£
¾ßÌåËüÃǽ«Ôںδ¦Óã¿ÈçºÎÓü°ËüÃÇÓÐʲôÇø±ð£¿ÕâÓ¦¸ÃÊǺܶàÈË¿´µ½Ëü¶¼»áÏëµ½µÄÎÊÌâ¡£ÏÂÃæÒ»ÆðÀ´¿´¿´°É¡£
ͨ³£ ......