• 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

Can I call a servlet directly from HTML

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using Tomcat 5.5.4. I'm trying to call a servlet that retrieves data from the database. I want to set up a hotlink(hyperlink) on the main web page but can't get it to call the servlet. I've set up the servlet entry in the web.xml file and it works if I open a form with a submit button. I just want a hotlink though to get the data. Does anyone know if this is possible?
Thanks
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your servlet override doGet?
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Patrick yes, you can definately call your servlet directly from HTML infact that depends on which Method of the Form you call as there are 2 method types POST / GET.

To call a servlet from an HTML you can put the servlet name in the Form Action and depending on the type of get or put doGet or doPut is called. But yeah name defined in the form action should exist in web.xml

Cheers,
Rahul
 
Patrick Lim
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks to everyone that replied! I have overridden doget with dopost but now that I think about it I don't need to override it for a select from the database. So I will change that and maybe it will work.
I don't want to use a form. I want to do a hotlink that calls the servlet directly. I can call the servlet directly if I use a form with a button so I know the web.xml file is set up correctly and the files are in the correct directories. I just can't seem to get it to work calling the servlet without a form. Any example code would be great!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Patrick Lim:
Hi,
I have overridden doget with dopost



I'm not sure what that means.
Also doPost and doGet are case sensitive.

In order for your servlet to respond to a form posting, you have to override the doPost method. To hit it directly, you have to override the doGet method.

If you want the same code to respond to both types of requests, just call one from the other.


Example:
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would take the form that works and change the method to "GET" - then carefully examine the URL that this constructs. That is the way your link will have to be formulated.
Bill
 
You get good luck from rubbing the belly of a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic