This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Calling a servlet from a html page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling a servlet from a html page" Watch "Calling a servlet from a html page" New topic
Author

Calling a servlet from a html page

sreejith parambath
Greenhorn

Joined: Nov 19, 2006
Posts: 8
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

Joined: Nov 19, 2006
Posts: 8
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

Joined: Dec 06, 2005
Posts: 1321

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.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

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/".



Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
 
 
subject: Calling a servlet from a html page
 
Similar Threads
Servlet
Application server
Problem with recognizing the class files
how to create our own wbapplication
html vs servlet