• 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

unable to deploy servlets in tomcat

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am unable to deploy my servlet in tomcat if I make following changes. Otherwise if i save my class files in examples/WEB-INF/classes it works fine. Kindly let me know where I am wrong.
Step1: I made a directory webapps/mydir
Step2: Now i made changes in conf/server.xml file with
<Context path="/mydir" docBase="mydir" debug="0" reloadable="true"> </Context>
Step3: Now i put my servlet class file in /mydir/WEB-INF/classes Directory.
Step 4: I made web.xml and put it into mydir/WEB-INF directory with content as---->>
<servlet>
<servlet-name>counters</servlet-name>
<servlet-class>mydir/counters</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>counters</servlet-name>
<url-pattern>/counters</url-pattern>
</servlet-mapping>
Step 5: run the servlet
http://localhost:8080/mydir/counters
but if i run my servlet from the default one it works:
http://localhost:8080/examples/servlet/counters
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've changed the / to a . in your servlet-class tag. Also, it should be the fully qualified class name, so it's not the directories, rather than packages. (if it happens to be in the 'mydir' package, then it would be mydir.counters). Also, you've got the web-app tags?

And you're restarting tomcat, right?
[ May 03, 2004: Message edited by: Mike Curwen ]
 
shishir gupta
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
yes, i have <web-app> tag. mydir is not a package, it is a directory in which i have WEB-INF folder and web.xml file. I changed it but still giving error 404page not found. Kindly let me know where i am wrong.
<web-app>
<servlet>
<servlet-name>counters</servlet-name>
<servlet-class>/counters</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>counters</servlet-name>
<url-pattern>/counters</url-pattern>
</servlet-mapping>
</web-app>
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<servlet-class>counters</servlet-class>
not
<servlet-class>/counters</servlet-class>

you are supposed to specify a class name, not a path.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You need to specify a package for ANY Java class used in servlets or JSP AND put the class file under WEB-INF/classes with the package directory structure.
The reason is (as I understand it) if the class loader sees a bare class without a package it only looks in the "current" directory - which with a servlet engine JVM can be anywhere.
Bill
reply
    Bookmark Topic Watch Topic
  • New Topic