How to call a servlet
4 posts in topic
Flat View  Flat View

Posted By:   ajay_gupta
Posted On:   Tuesday, February 12, 2002 10:23 AM

I am using Tomcat for my application. I had created a folder called TestEditor, in webapps and put my class Hello.class in webapps/TestEditor/Web-inf/classes diretory and set context path also as "/TestEditor" and docbase "TestEditor" but when I call the servlet through browser as http://localhost:8080/TestEditor/servlet/Hello. it doesn't work.
Do i need anyother changes somewhere or Do I need to set the classpath ?
When I run javap -classpath TestEditor/web-inf/classes Hello , it says Hello class not found ..

Any kind of help would be appreciated.

Re: How to call a servlet

Posted By:   Laurent_Mihalkovic  
Posted On:   Monday, February 18, 2002 01:14 PM

If i may suggest, read the Servlet specification. You will see that provided that your context is /TestEditor, you should then call you servlet with http://localhost:8080/TestEditor/Hello, instead of http://localhost:8080/TestEditor/SERVLET/Hello. You should also declare the servlet inside the web.xml file.

it is not that complicated once you visualize how the URL is built:

http://localhost - tell which machine

8080 - to indicate where Tomcat is listening (first chance of misconfiguration)

TestEditor - this is to help tomcat (or any other servlet container) discriminate between all the .WAR files that are deployed on the machine (what the spec refers to as 'web application')

Hello - a web application can be built with multiple servlets, so the container needs to have a 'shorthand' way of refering to each one individually. The container will lookup this name into its internal list of servlets, which will tell it which java class to load and execute. The name does not have to be the same as the class name. For example:
http://localhost:8080/TestEditor/SERVLET/Hello could refer to package.package.package.MyClass.class

try to get in the habit of declaring all your servlets in the web.xml file (the application descriptor file, described in the servlet spec), instead of relying on the default loader. That will help you get a sense of how servlets are identified and called.

hope that helped

Re: How to call a servlet

Posted By:   Anonymous  
Posted On:   Wednesday, February 13, 2002 12:09 AM

Be advised that the WEB-INF directory MUST BE all uppercase, since Java is a case sensitive language.


Re: How to call a servlet

Posted By:   David_Liu  
Posted On:   Tuesday, February 12, 2002 12:43 PM

Another thing to remember is that if you are building a new directory instead of using webapps/root, then you need to modify the web.xml. It should be located in "webapps/TestEditor/Web-inf/web.xml"

Make sure you set your servlet name.

foo Servlet Name

foo Servlet Location

good luck

Re: How to call a servlet

Posted By:   Tonio_Caputo  
Posted On:   Tuesday, February 12, 2002 11:35 AM

I'm not at my office and I can not
test what you're telling exactly
but first of all I remember
(until Tomcat 3.x at least) that
you must restart it after
changing your classes.

I understand this is
the only way for Tomcat to
recognize your new TestEditor Application or your new classes.

I hope this will help you.

About | Sitemap | Contact