How to access servlet from html form action in J2EE application server
Hi
I have created a servlet which is very simple.I created an index.htm and used <FORM ACTION="exmapleServlet" METHOD="POST"
in web.xml I put
><servlet>
<servlet-name> exampleServlet</servlet-name>
<servlet-class> myservlet.FirstServlet</servlet-class>
The directory structure is
TopDir->index.html
WEB-INF -> web.xml
classes/myservlet/FirstServlet.class
I created a .war in top level directory using jar -cvf myservlet.war index.html WEB-INF
Now I deployed this war file onto J2EE app server with context "myservlet",and launched the application.It shows index.html.But when I press submit button it gives error message that myservlet/exampleservlet not found.
How to solve this problem.Please help me.
Also tell me what is the rule for putting data in FORM ACTION for J2EE app server and what to write in servlet-class in web.xml.
Does it matter what context name we give while deploying.
Thanks a lot
[1044 byte] By [
mmittaka] at [2007-11-27 5:12:54]

# 1
you also need a servlet-mapping in your web.xml file to map the servlet to a specific url pattern that will cause the server to invoke it. This would be it for your servlet:
<servlet-mapping>
<url-pattern>/myservlet/ExampleServlet</url-pattern>
<servlet-name>exampleServlet</servlet-name>
</servlet-mapping>
However, two things:
1) there seem to be spaces in your servlet-name and servlet-class lines, you don't want those
2) watch the cases in the names you choose, everything is case-sensitive
I suggest you do some research into the servlet-mapping for other possibilities and restrictions.
# 3
Hi i want to know whether or can a servlet be called from an html directly with our mentioning any urlname in web.xml
because to my knowledge i think that the urlname and the class which it is pointing to might be stored in some key value combination so that when ever a requeste been send to server with the urlname the server just takes out the corresponindg class name of that specified url and starts calling it
Any suggestion on this? how can we call that servlet with out an entry in web.xml ?