wood burning stoves 2.0*
The moose likes Servlets and the fly likes straing servlet URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "straing servlet URL" Watch "straing servlet URL" New topic
Author

straing servlet URL

jbig zala
Greenhorn

Joined: Sep 20, 2004
Posts: 11
Hi Smart Cattles,

I m facing very strange prob with web.xml and servlet names.

I have created context name 'abc' and servlets in abc\WEB-INF\classes folder.
To Access servlet named helloworld i have to use url named
http://localhost:8080/abc/servlet/helloworld

I don't won't to show name of my servlet. so i changed
<servlet>
<servlet-name>Helloabc</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
and accessed it using
http://localhost:8080/abc/servlet/helloabc
but it gives me 404 error.
it works only if i changed servlet-name as HelloWorld again .
Where i mistaken ?
is it possible to access HelloWorld servlet using URL like
http://localhost:8080/abc/hello.html
if yes, how ???
John Mallavalli
Ranch Hand

Joined: Apr 24, 2002
Posts: 46
Hey Smartie,

You need to do 2 things.
1. In the web.xml, you need to provide a servlet element with the fully qualified class name of the servlet and the name with which you want to access that particular servlet. For example, if you have a servlet class as abc.hello.HelloWorld and if you would like to call it as "hello" then the entry in the web.xml would be as follows:
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>abc.hello.HelloWorld</servlet-class>
</servlet>

2. You need to map the servlet for an url path so that the servlet can be accessed. For example, if you want to access this servlet by typing "http://myserver:8080/abc/myhello.html", then you need to add a "servlet-mapping" element in the web.xml as follows:
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/myhello.html</url-pattern>
</servlet-mapping>

You can obtain more information on this by reading the Servlet Specification. You can download the latest specification document here.
Happy Reading..!!

- John


Do not let what you cannot do interfere with what you can do !!<br /> <br />SCJP & SCWCD 1.4
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
and accessed it using
http://localhost:8080/abc/servlet/helloabc
but it gives me 404 error.

This indicates that you need to read the invoker servlet FAQ.
Books and articles dating from before the invoker was turned off by default in Tomcat must surely be the cause of at least half of all beginner problems.
Bill
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

"Dev Smart"-

This is your second warning.

Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
jbig zala
Greenhorn

Joined: Sep 20, 2004
Posts: 11
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

faqs suggest that i have to uncomment above tags. It have tried, but gives me 404.
what's wrong ?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Quick Learner",
sorry to nag, but your display name still does not meet our requirements

We require display names to be two words: your first name, a space, then your last name. Obviously fictitious names are not allowed.

We appreciate your co-operation.
thanks,
Dave.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: straing servlet URL
 
Similar Threads
The requested resource is not available
Tapestry and Tomcat
Cannot invoke servlet by name!
How to debug a servlet
Running Servlets, have a question