• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat example jsp working. Example servlet not working

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
michael tall
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Drop the /servlet prefix.
 
michael tall
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dropped the /servlet from URL and entered
It didn't work
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You also forgot the leading / in your mapping.
 
michael tall
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. You might also want to review your naming. sn and dn are not very good and descriptive choices.
 
michael tall
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added slash in the mapping and it worked fine. Thanks much for your timely help.
reply
    Bookmark Topic Watch Topic
  • New Topic