1.å¦ä½ä½¿ç¨eclipseå建ç®åçservlet
2.å¦ä½è§£å³ä¾èµå
servlet-apiå容å¨èªå¸¦servletçjarå
çå²çª
3.eclipseä¸httpservletç±»ç¨ä¸äºï¼åºè¯¥å¯¼å
¥ä»ä¹å®è£
å
ï¼
å¦ä½ä½¿ç¨eclipseå建ç®åçservlet
servletéè¦ç»§æ¿HttpServletæ¥å建ï¼æä»¥å¿ é¡»æjarå å¼è¿é¡¹ç®ä¸æ¥ã1ãè¿jarå ï¼æ¹æ³å¦ä¸ï¼
å¨eclipseä¸æ°å»ºä¸ä¸ªé¡¹ç®-->项ç®å³é®-->Build Path-->Add External Archives-->tomcat-->lib-->servlet-api.jar
2ãå建servletï¼
å¨é¡¹ç®éé¢æ°å»ºä¸ä¸ªç±»ï¼ç»§æ¿HttpServletï¼éådoGgetæ¹æ³ï¼æ¤æ¶ä¸ä¸ªservletå·²ç»å»ºæ(éè¦ä½¿ç¨çè¯è¿éè¦ä»¥ä¸æ¥éª¤)ã
3ãå¨tomcatä¸é¨ç½²servlet(servletæ¯ä¸ä¸ªç»ä»¶ï¼éè¦ç±tomcat访é®)
å¨tomcatçwebappsæ件æ°å»ºä¸ä¸ªæ件夹(项ç®å)ï¼éé¢å»ºç«ä¸ä¸ªWEB-INFæ件夹ï¼ç¨æ¥æ¾servletç¼è¯åç.classæ件åweb.xmlé ç½®æ件ï¼å¦ä¸å¾ï¼
4ãé ç½®web.xmlé ç½®æ件
5ãå¯å¨æå¡å¨
6ãå¨æµè§å¨å°åæ éé¢è¾å ¥urlå°åæ¥è®¿é®servletçdoaGetæ¹æ³ã
å¦ä½è§£å³ä¾èµå servlet-apiå容å¨èªå¸¦servletçjarå çå²çª
解å³ä¾èµå servlet-apiå容å¨èªå¸¦servletçjarå çå²çªçåæ³ï¼
å¨webåºç¨ä¸ï¼WEB-Infç®å½ä¸ï¼ä¹å¯ä»¥å»ºç«libåç®å½ï¼å¨æ¤åç®å½ä¸å¯ä»¥åæ¾åç§jaræ件ï¼è¿äºjaræ件åªè½è¢«å½åwebåºç¨è®¿é®ãå ¶ä¸ï¼å¨web-infç®å½ä¸çlibä¸classesç®å½ï¼Tomcatç±»è£ è½½å¨å è£ è½½classesç®å½ä¸çç±»ï¼åè£ è½½libç®å½ä¸çç±»ãå 为类ååæ¶ï¼classesä¼å ã
å ¶ä¸jspè¿è¡æ¶ï¼æ¥æ¾classç顺åºä¸ºï¼é¡¹ç®æ件夹ï¼WEB-INF\libï¼â>容å¨æ件夹ï¼tomcat\common\libï¼â>jdkæ件夹(jdk\jre\lib\ext)
Tomcatæ¯ä¸ç§åä¸å¯»æ¾çå±æ¬¡ç»æï¼ä¹æåä¸çï¼æè æ¯å¯é ç½®çã
Tomcatçclasså è½½çä¼å 顺åºä¸è§
ââââ-
1.æå æ¯$JAVA_HOME/jre/lib/ext/ä¸çjaræ件ã
2.ç¯å¢åéCLASSPATHä¸çjaråclassæ件ã
3.$CATALINA_HOME/common/classesä¸çclassæ件ã
4.$CATALINA_HOME/commons/endorsedä¸çjaræ件ã
5.$CATALINA_HOME/commons/inä¸çjaræ件ã
6.$CATALINA_HOME/common/lib ä¸çjaræ件ã(JDBC驱å¨ä¹ç±»çjaræ件å¯ä»¥æ¾å¨è¿éï¼é¿å é 置好æ°æ®æºå´æ¾ä¸å°JDBC Driverçæ åµã)
7.$CATALINA_HOME/server/classesä¸çclassæ件ã
8.$CATALINA_HOME/server/lib/ä¸çjaræ件ã
9.$CATALINA_BASE/shared/classes ä¸çclassæ件ã
.$CATALINA_BASE/shared/libä¸çjaræ件ã
.åèªå ·ä½çwebapp /WEB-INF/classesä¸çclassæ件ã
.åèªå ·ä½çwebapp /WEB-INF/libä¸çjaræ件ã
classçæ寻顺åºå¦ä¸
ââââ-
/WEB-INF/classes of your web application
/WEB-INF/lib/*.jar of your web application
$CATALINA_HOME/common/classes
$CATALINA_HOME/common/endorsed/*.jar
$CATALINA_HOME/common/in/*.jar
$CATALINA_HOME/common/lib/*.jar
$CATALINA_BASE/shared/classes
$CATALINA_BASE/shared/lib/*.jar
âââââ
å æ¤æ¾å¨ä¸åwebappéçclassæ件ï¼ä¼è¢«classloaderå è½½æä¸åçå®ä¾ã
å¨ä¸åçwebappå è½½ç¸åç±»åçç±»äºä¸å½±åã
ä½æ¯æ³¨æï¼ä»¥ä¸å åå¼å¤´çclassä¾å¤ï¼
javax.*
org.xml.sax.*
org.w3c.dom.*
org.apache.xerces.*
org.apache.xalan.*
ps,双色球过滤源码注æ.å¨å个jarä¸ç\META-INF\MAINFEST.MFæ件éClass-Pathé®å¼å¯¹ï¼ä¹ä¼æä¾jarçå è½½ä¼å 顺åºã
ä¾å¦æjarçMAINFEST.MFå 容å¦ä¸ï¼
Manifest-Version: 1.0
Created-By: Zianed
Class-Path: commons-beanutils.jar
Class-Path: commons-collections.jar
Class-Path: commons-dbcp.jar
Class-Path: commons-digester.jar
Class-Path: commons-logging.jar
Class-Path: commons-pool.jar
Class-Path: commons-services.jar
Class-Path: commons-validator.jar
Class-Path: jakarta-oro.jar
Main-Class: Test
eclipseä¸httpservletç±»ç¨ä¸äºï¼åºè¯¥å¯¼å ¥ä»ä¹å®è£ å ï¼
åºè¯¥å¯¼å ¥tomcatââlibç®å½ä¸é¢çtomcat-api.jaræ件HttpServletçåè½
HttpServleté¦å 读åHttp请æ±çå 容ãServlet容å¨è´è´£å建HttpServlet对象ï¼å¹¶æHttp请æ±ç´æ¥å°è£ å°HttpServlet对象ä¸ï¼å¤§å¤§ç®åäºHttpServlet解æ请æ±æ°æ®çå·¥ä½éãHttpServlet容å¨ååºWeb客æ·è¯·æ±æµç¨å¦ä¸ï¼
1ï¼Web客æ·åServlet容å¨ååºHttp请æ±ï¼
2ï¼Servlet容å¨è§£æWeb客æ·çHttp请æ±ï¼
3ï¼Servlet容å¨å建ä¸ä¸ªHttpRequest对象ï¼å¨è¿ä¸ªå¯¹è±¡ä¸å°è£ Http请æ±ä¿¡æ¯ï¼
4ï¼Servlet容å¨å建ä¸ä¸ªHttpResponse对象ï¼
5ï¼Servlet容å¨è°ç¨HttpServletçserviceæ¹æ³ï¼æHttpRequeståHttpResponse对象ä½ä¸ºserviceæ¹æ³çåæ°ä¼ ç»HttpServlet对象ï¼
6ï¼HttpServletè°ç¨HttpRequestçæå ³æ¹æ³ï¼è·åHTTP请æ±ä¿¡æ¯ï¼
7ï¼HttpServletè°ç¨HttpResponseçæå ³æ¹æ³ï¼çæååºæ°æ®ï¼
8ï¼Servlet容å¨æHttpServletçååºç»æä¼ ç»Web客æ·ã