aspose file tools*
The moose likes Servlets and the fly likes calling servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "calling servlet" Watch "calling servlet" New topic
Author

calling servlet

Naveed Ali
Ranch Hand

Joined: Aug 30, 2002
Posts: 41
Hi all!

I successfully load the application(starting file = index.html) when i run tomcat 4 and enter the Url. But i am unable to call the servelt from index.html. What should be the solutions in following?

- Calling from a hyperlink.
- Can i call it by using 'Form' or something like 'Action' from html file.
- Is servlet-mapping necessary in above two cases. If yes then should i call the actual class or mapping class name.Plz insert a line or two of html code as an example.

Assuming the classes are in directory WEB-INF/Classes/Classes/

I have tried in various patterns but it returns error no. 404 while i can successfully load and run the servlets if i call it directly from Url wihtout using index.html.

Thnx in advance.
Naveed
asirob civokviz
Greenhorn

Joined: Jun 12, 2004
Posts: 24
well,
when calling servlet use
./servlet/servletpackage.servletname

for example if your servlet is in sun.com package
and its name is ExampleServlet
you should call it
./servlet/sun.com.ExampleServlet

all servlet classes should be placed in web-inf/classes/
directory
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
/servlet/servletpackage.servletname

No no no no - do NOT use the invoker servlet (implied by /servlet/) - it isn't even turned on in Tomcat 4 on. See the invoker servlet FAQ here at the ranchhouse.
Nothing but confusion can come of relying on the invoker servlet to address a servlet.
Bill
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
Assuming the classes are in directory WEB-INF/Classes/Classes/


First of all you must store the class files under WEB-INF/classes and try invoking the servlet using any of the standard procedure.

Secondy, according to your WEB-INF directory structure the Classes directory under /Classes will be treated as a package path.

for example,

package Example;

{
your class definitions
}

the dir structure should be WEB-INF/classes/Example/<your class file> and you must invoke the servlet using the package name.servletname.

the dd format is as follws.

<servlet>
<servlet-name>example</servlet-name>
<servlet-class>ExampleServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>example<servlet-name>
<url-pattern>/servlet/ExampleServlet</url-pattern>
</servlet-mapping>

hope this helps.

regards,
ravi.
[ June 15, 2004: Message edited by: Ravikumar Jambunathan ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Can you point to a good doc on the xml configuration you showed? I've seen several examples and have one or two up & running in Tomcat/Eclipse but the entries don't make sense to me yet. Thanks!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
hi james,

hope you have misunderstood. I have given only the <servlet> and <servlet-mapping> portion as an example. I presume, you have misunderstood because of the sentence "dd format". I did not mean the web.xml format.

hope it is clear now.

regards,
ravi.
Naveed Ali
Ranch Hand

Joined: Aug 30, 2002
Posts: 41
well, i have just missed one point that i have created new application by creating new directory 'application' under the 'webapps\ROOt\' dir. I have given the context path as '/application'. So the exact directory structure in my case is ROOT/application/classes/classes and not the previous one i had given. The WEB-INF dir is under the 'application' dir. I have packaged my servlet class in package named 'classes'. Here i am posting the mapping.

<servlet>
<servlet-name>Helloservlet2</servlet-name>
<servlet-class>classes.servlet2</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Helloservlet2<servlet-name>
<url-pattern>/classes/classes/Helloservlet2</url-pattern>
</servlet-mapping>

i had given '/classes/classes/Helloservlet2' in the hyperlink which gave me error 404.

regards

naveed
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Well, webapps\ROOT is already a web application - it has a WEB-INF and web.xml etc.
You can't create another web application under ROOT, you must create it under webapps. Assuming your application name is application and your servlet is in the "classes" package and the servlet class name is indeed "servlet2" like it says in your web.xml, your directory structure should be:


For documentation of how to fix your web.xml - why not go to the source?
http://java.sun.com/products/servlet/reference/api/index.html
and
http://java.sun.com/products/jsp/reference/api/index.html

Bill

[ June 15, 2004: Message edited by: William Brogden ]
[ June 15, 2004: Message edited by: William Brogden ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling servlet