It's not a secret anymore!
The moose likes Servlets and the fly likes Servlets from an HTML anchor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets from an HTML anchor" Watch "Servlets from an HTML anchor" New topic

Servlets from an HTML anchor

Jim Moffat

Joined: Sep 18, 2006
Posts: 8
In the Head First Java book, there are code snippets that suggest you can put a servlet on an anchor, as below (P. 627, if anyone is interested):

But the broswer won't bring up the HTML document. I get "page cannot be displayed." I am running Orion, so how should I code the link to the servlet class? The Cattle Drive code page showed the URL using "servlet/classname" and that didn't work either. So it is possible to link a servlet like that? The Head First book was not too clear on this.
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
Jim Moffat, Have you configured your web.xml file for this Servlet? Please post that configuration here.

My blood is tested +ve for Java.
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
Let us assume the context root of your web application is myapp.

Also your server is on localhost port number 8080.

You can access the application using
http://localhost:8080/myapp/servlets/MyServletA (incase the anchor is in a file on your local machine or on some other machine in the network)

or using a relative path (if the anchor is in a resource obtained from the same web application on the server in localhost) as /myapp/servlets/MyServletA

You should have a mapping in web.xml as follows




where servlet name is provided(in web.xml) as





Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
you can try

<a href="/servlets/MyServletA">Text</a>

instead of

<a href="servlets/MyServletA">Text</a>

say you want to visit something like

Sometime back I faced a similar problem.A similar code like what you have mentioned worked in OC4J / UNIX , but did not work in Websphere MVS.

Rahul Bhattacharjee
LinkedIn - Blog
Jim Moffat

Joined: Sep 18, 2006
Posts: 8
Thank you, all. I finally figured it all out. The Head First Java book is not very good at explaining this.
I agree. Here's the link:
subject: Servlets from an HTML anchor
It's not a secret anymore!