• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to execute servlet

 
Neo Wills
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am running tomcat 6 and the test page is seen fine (so I guess tomcat is running fine).

I have a test servlet process.java. I have placed it in this format:
/usr/share/tomcat6/webapps/sample/WEB-INF/classes/process.java

I have also placed the web.xml in /usr/share/tomcat6/webapps/sample/WEB-INF/web.xml . It looks like this:


I stopped and started tomcat after this.

When I run http://localhost:8080/sample/process it says it The requested resource /sample/process is not available.

Can some on help me identify what I am doing wrong?

Bharath
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There could be any reason for the error. The web.xml looks well formed to me. Can you show us the servlet code. Also check the tomcat logs (in /usr/share/tomcat6/logs directory) to see if there's any error stack trace. You can also check the tomcat console to see if there's any error when you use that URL in the browser...
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the class file must not be in the root directory which it is in this case. Not sure though.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


ALL classes used in servlets MUST be in a package. The reason being that the JVM will look for a class in the default (no)package in the "current" directory. You have NO control over the current directory in the servlet environment.

Years ago the first developers thought they would do new programmers a favor with the "invoker" servlet which would let you whip out a test servlet without a package and run it indirectly. Here is the ranch FAQ on the dreaded invoker.

So - always a package.

Bill
 
Neo Wills
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Putting it in a package did help. Thanks Bill. Also I moved this out to a separate directory and updated the conf file (without putting it in a package). That works as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic