Forums Register Login

straing servlet URL

+Pie Number of slices to send: Send
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 ???
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
"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
+Pie Number of slices to send: Send
<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 ?
+Pie Number of slices to send: Send
"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 don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1185 times.
Similar Threads
How to debug a servlet
The requested resource is not available
Tapestry and Tomcat
Running Servlets, have a question
Cannot invoke servlet by name!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 00:13:31.