• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to run servlet within tomcat

 
ellen berry
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys:
Do you know how to run servlet in Tomcat?
Thanks
ellen
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have installed Tomcat correctly, you get a bunch of examples and extensive documentation. Study the documentation and the examples. Download the Java servlet and JSP APIs from java.sun.com and study how web.xml is used to control servlets.
Bill
 
raymond yadao
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ellen!
the default directory of all the servlet programs in tomcat is in the <tomcat_home>/webapps/root/web-inf/classes. so you must put your .java and .class here.then you can try your programs by typing the url:http://localhost:8080/examples/<nameofyourprogram>
but if you want to create your own directory/folder, then create it in the folder webapps. webapps/<your folder> must contain two folders <meta-inf> and <web-inf>. in the <web-inf>, it also contains one folder <classes> and the web.xml. in the <classes> must put all your java programs(together with its classes).after this you must edit the web.xml so that tomcat knows where to find your .class.
for example i have a program name hello.java.
in the web.xml looks like:
<? xml version1.0 ?>
<webapps>
<servlet-name> hello </servlet-name>
<servlet-class> hello </servlet-class>
....
<servlet-name> hello</servlet-nmame>
<url-pattern> hello </url-pattern>
</webapps>
run your application by typing the url : http://localhost:8080/<yourcreatedfolder>/<yourprogram>

hope this helps.

raymond
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!