File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Calling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling "/servlet/MyServlet" from HTML form" Watch "Calling "/servlet/MyServlet" from HTML form" New topic

Calling "/servlet/MyServlet" from HTML form

Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
Hi, I have a question about calling a servlet from a HTML form from local host. I have a HTML page that is at
And it's supposed to call "/servlet/MyServlet" in its form. But tomcat can not find it! Should I change it to ""?
Thank you in advance.
Raghavendra Holla
Ranch Hand

Joined: Jun 02, 2000
Posts: 58
Hi Bob,
Try "http://localhost:8080/servlet/MyServlet" or Just "servlet/MyServlet" (I Removed a '/').
Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
Hi, I tried "servlet/MyServlet" in FORM ACTION, but tomcat can not find it.
Arvind Karanth

Joined: Nov 21, 2000
Posts: 7
Hi Bob,
Hope You have done the following before trying to run the servlet.
[1] copy the .class file of the servlet to :
[2] Start the server i.e. execute jsdk1.2/startserver.bat file

Once you have done all this write this in the HTML file:
<FORM METHOD="POST" ACTION="http://localhost:8080/servlet/MyServlet">
When you click on the submit button on the HTML page....I hope it works.

[This message has been edited by Arvind Karanth (edited November 23, 2000).]
Ranch Hand

Joined: Oct 20, 2000
Posts: 68
Hi Bob Moranski,
You are doing basic mistake in invoking servlets.
First of all why you have kept "ThisHtml.html" in "classes" directory ?. The "classes" dir should not contain HTML files it should contain your servlet files or pakage.
Have you defined "server.xml" which is in TOMCAT configuration dir ?. I thing you are using pakages in your servlets, hence your URL will be
Keep your HTML or JSP files in "\ch2\ " directory
If you keep your MyServlet.class in "\classes\ch2\" directory then The first line in your will be "package ch2;"
Include the following in your "server.xml" file
<Context path="/ch2"
isWorkDirPersistent="false" />

I agree. Here's the link:
subject: Calling "/servlet/MyServlet" from HTML form
It's not a secret anymore!