aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets from an HTML anchor" Watch "Servlets from an HTML anchor" New topic
Author

Servlets from an HTML anchor

Jim Moffat
Greenhorn

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: 3636
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
<servlet-mapping>

<servlet-name>ServletNameXXX</servlet-name>

<url-pattern>/servlets/MyServletA/*</url-pattern>

</servlet-mapping>

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

<servlet>

<servlet-name>ServletNameXXX</servlet-name>

<servlet-class>com.abc.def.somepkgname</servlet-class>

</servlet>


http://www.skillassert.com


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

http://cool.com/myApp/servlets/MyServletA

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
Greenhorn

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlets from an HTML anchor