• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling a servlet from a html page

 
sreejith parambath
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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/".

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic