aspose file tools*
The moose likes Servlets and the fly likes how can test my servlet  in tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how can test my servlet  in tomcat" Watch "how can test my servlet  in tomcat" New topic
Author

how can test my servlet in tomcat

jimmy
Greenhorn

Joined: Nov 06, 2004
Posts: 18
I compile my first servlet and try to use tomcat. but get really tired on sintalling the servlet.
I got two version tomcat : 3.4 and the latest one 5.5.4 . both server can run very well.
As my ebook using the old tomcat 3.o as the sample. I just want to know where shall I put my .class files and then I can test them by putting url like http://localhost/servlet/**
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
Tomcat comes with extensive documentation - if you can get Tomcat examples to run, you can read everything you need to know by picking the right links from the startup page.
Start at http://localhost/tomcat-docs/index.html
Bill
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Also, the old convention of using http://DOMAIN/servlet/PACKAGE/CLASS is all but gone. The invoker servlet is still present but it's declaration and mapping are commented out in the Tomcat configuration files.
See:
http://jakarta.apache.org/tomcat/faq/misc.html#evil
for more details.
You should manually map all of your servlets in your app's deployment descriptor (web.xml).

SimpleServlet at http://simple.souther.us has an example of a mapped servlet, all WARed up and ready to run.

Also the "First Web App" tutorial on Tomcat's site does a good job of explaining this.
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/appdev/index.html


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
jimmy
Greenhorn

Joined: Nov 06, 2004
Posts: 18
it seems tomcat changed a lot from version 3.0, my ebook is based on tomcat 3.0 and I can not follow the way to just put a .class file to some dir like installdir/webpages/WEB-INF/classes. and then, just use http://localhost/servlet/** to test that servlet.
as I am very new on tomcat and servlet , so, normally , how to test your servlet and jsp file in tomcat then.
I run the example and I notice the structure of a .war is quite complex in some way.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

They're not complex. You just need to have a WEB-INF directory in the base of the war. Put a copy of web.xml in that file. Your compiled and packaged servletes go in WEB-INF/classes and any java libraries (jar files) go in WEB-INF/lib.

Go to http://simple.souther.us and grab SimpleServlet.war. Put it in the webapps directory of Tomcat and it should run. Use that as a reference.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
The most confusing change from Tomcat 3 to the current 4 and 5 has to do with addressing your class with the /servlet/ URL. The Invoker servlet that permitted this simplified approach was on by default in Tomcat 3 but is now off. Now you have to either turn invoker on specifically or configure using the web.xml file. The invoker is described in more detail in this ranch FAQ.
The idea with the invoker was to make it real easy to get your first servlet running, but the bad effect was that it prevented using the standard configuration method - which you would have to learn anyway.
Bill
jimmy
Greenhorn

Joined: Nov 06, 2004
Posts: 18
you know, I just pass the programmer certification last week. it seems that I can not test jsp and servlet in the same way that I test standard java applications. as they are treat as web application and need a web server to containing and supporting it. so, I can not just put raw code files. deployment steps need to be followed.
also, I can just get an simple war file and change its setting to adapt my code then, test my code in this way, but it is not the way people work on it. am I right ?
I am not a programmer before, but I believe I like it in some way. it took me one month and a half to pass the scjp. I don't know when I can pass this one. it seems more difficult .
thank you guys, I know I can learn a lot here. your quick reply really give me confidence!!!
Thank you..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you want a great example of a 'best practice' development approach for JSP/Servlets, checkout the "First Web App" tutorial on Tomcat's site:
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/appdev/index.html

It was written by Craig McClannahan, one of the original contributors to Tomcat itself.

Another approach is to use an embedded container from within an IDE. think Eclipse, JBuilder, and Netbeans all have an embedded version of Tomcat.
 
 
subject: how can test my servlet in tomcat