File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Tomcat example jsp working. Example servlet not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Tomcat example jsp working. Example servlet not working" Watch "Tomcat example jsp working. Example servlet not working" New topic
Author

Tomcat example jsp working. Example servlet not working

michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I installed Tomcat 6.xxx on Windows XP. I understand Tomcat 6.0\webapps\ROOT is the default webapps directory. Other subdirectories in webapps directory are docs, host-manager and manager. ROOT has WEB-INF subdirectory and couple of .GIF, .xml, .html, .jsp etc files. I put couple of test jsp and html files and they worked fine. I, however, am unable to understand where to place a compiled servlet file and test. Initially I placed directly in ROOT along with jsp, html files but it didn't work. I then created a classes subdirectory in WEB-INF and placed the compiled servet in classes subdirectory of WEB-INF. Still didn't work. I modified the default web.xml file that is available in WEB-INF directory by adding <servlet> and <servlet-mapping> tags for the compiled servlet. Still no use.
Does anyone know what exactly needs to be done to make the example servlet work?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

Your post is very short on details.

Exactly where did you place the compiled class? Is it in a package other than the default? What URL are you using to access it? is it properly mapped in the web.xml deployment descriptor? And so on...


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I assumed webapps\ROOT is the default web application directory because there are couple of jsp, GIF files etc. I placed my own example HTML and jsp files in webapps\ROOT and they worked fine. I am trying to figure out how to make an example servlet work. webapps\ROOT\WEB-INF directory doesn't contain classes subdirectory. It has a web.xml file. To the web.xml file, I added <servlet> and <servlet-mapping> tags for the example servlet and then created a classes subdirectory in webapps\ROOT\WEB-INF and placed the example servlet class file in webapps\ROOT\WEB-INF\classes directory. I restarted Tomcat and tested the example servlet from the browser using the url:. web.xml entry is:
Wondering where I'm going wrong
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

Drop the /servlet prefix.
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I dropped the /servlet from URL and entered
It didn't work
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

You also forgot the leading / in your mapping.
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
Probably this is elementary. But can you make it clearer for me? Should I edit the web.xml? Where should I add the slash?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

P.S. You might also want to review your naming. sn and dn are not very good and descriptive choices.
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I added slash in the mapping and it worked fine. Thanks much for your timely help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat example jsp working. Example servlet not working
 
Similar Threads
How to debug a servlet
Where does this package go?
trying to get a simple bean example to work using Tomcat and jsp
JSP page error (Unable to compile class for JSP ) HTTP Status 500 -
strange instructions for servlet setup