• 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

Calling a servlet from a html page

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all,
i am using apache tomcat 5.5.11 and i need some assistance regarding this topic.

i have a class which needs to be called from a html(i.e, in the action i need to pass a link which will call up the servlet)
if it was in the case of j2ee server, i can call the servlet with an alias, but i dont know how to do it with tomcat.

moreover, where shoud be the class file stored, because, in the earlier versions, the class file used to be stored in the classes directory found under webapps directory.

i am in need of this and would be thankful if any one could revert back with the steps in which i can accomplish my requirement.


regards,

sreejith
 
sreejith parambath
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
got it guys,
You need to put the .class file in the classes folder within WEB-INF(if the folder does not exist,as it will not, you need to make it) and the respective jsp or html in the root directory.
then you need to map the servlet in the web.xml which is available in the ROOT directory and would appear like this:-



when you are calling the servlet, in the form you need to specify like this as given below:

where myservlet is referring to the url-pattern in the web.xml file.


regards and happy coding with servlets.

sreejith
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First you need to compare your directory structure with below structure to check whether its correct or not.



Originally posted by sreejith parambath:
i have a class which needs to be called from a html(i.e, in the action i need to pass a link which will call up the servlet)



then call your servlet from html page by applying this form action code.



hope it helps.
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is enough to mention like below, don't need to give the full path. Browser will append "myservlet" to your context URL "http://localhost:8080/".

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic