• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

straing servlet URL

 
jbig zala
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
jbig zala
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic