本文发表在 rolia.net 枫下论坛1) You never run servlets in browsers. You saying of running servlets in browser is incorrect. We run servlets on the server, and use the browser to observe the effects.
2) If you want to generate the HTML stuff, web pages, your servlet should extend javax.servlet.http.HttpServlet. Then, you need to extend doGet() or doPost(), or both of them. javax.servlet.GenericServlet is generally used to do some tasks behind the curtain, not for generating html stuff.
3) I suggest you look through all the files under C:\jakarta-tomcat\webapps\example. In particular, look into C:\jakarta-tomcat\webapps\example\WEB_INF\web.xml,
in wich you can learn how to configure servlets.
4) In Tomcat, there are several "Contexts". If
your context is named chengdu, it means there is C:\jakarta-tomcat\webapp\chengdu.
For this context, its servlet context is C:\jakarta-tomcat\webapps\chendu\WEB_INF\classes\.
Now if your servlet is called com.abc.greeting.Hello, the class file should stay at C:\jakarta-tomcat\webapps\chengdu\WEB-INF\classes\com\abc\greeting\Hello. To access this servlet, you should hit
http://127.0.0.1:8080/chengdu/servlet/com.abc.greeting.Hello. If you think this URL is ugly-looking, you should edit C:\jakarta-tomcat\webapps\chengdu\WEB-INF\web.xml to give this servlet a better-looking name.
Yoou may compare what I said here to the examples in tomcat.
5) It seems that you have not used the user manual in the tomcat. If you look into the manual in detail, you would have saved a lot of time on guessing work.更多精彩文章及讨论,请光临枫下论坛 rolia.net
2) If you want to generate the HTML stuff, web pages, your servlet should extend javax.servlet.http.HttpServlet. Then, you need to extend doGet() or doPost(), or both of them. javax.servlet.GenericServlet is generally used to do some tasks behind the curtain, not for generating html stuff.
3) I suggest you look through all the files under C:\jakarta-tomcat\webapps\example. In particular, look into C:\jakarta-tomcat\webapps\example\WEB_INF\web.xml,
in wich you can learn how to configure servlets.
4) In Tomcat, there are several "Contexts". If
your context is named chengdu, it means there is C:\jakarta-tomcat\webapp\chengdu.
For this context, its servlet context is C:\jakarta-tomcat\webapps\chendu\WEB_INF\classes\.
Now if your servlet is called com.abc.greeting.Hello, the class file should stay at C:\jakarta-tomcat\webapps\chengdu\WEB-INF\classes\com\abc\greeting\Hello. To access this servlet, you should hit
http://127.0.0.1:8080/chengdu/servlet/com.abc.greeting.Hello. If you think this URL is ugly-looking, you should edit C:\jakarta-tomcat\webapps\chengdu\WEB-INF\web.xml to give this servlet a better-looking name.
Yoou may compare what I said here to the examples in tomcat.
5) It seems that you have not used the user manual in the tomcat. If you look into the manual in detail, you would have saved a lot of time on guessing work.更多精彩文章及讨论,请光临枫下论坛 rolia.net