Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets from an HTML anchor

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim Moffat, Have you configured your web.xml file for this Servlet? Please post that configuration here.
 
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jim Moffat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, all. I finally figured it all out. The Head First Java book is not very good at explaining this.
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic