• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTML form

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I tried to put two parameters from html form and get it to the servlet and then display it.

my servlet is located in C:\Tomcat\apache-tomcat-6.0.18\webapps\chapter1\WEB-INF\classes\LoginServlet.class

my html form is located in C:\Tomcat\apache-tomcat-6.0.18\webapps\name.html

i put html form action as <form method="GET" action="/chapter1/LoginServlet">


my web.xml file is as below .but when i put two parameters and click submit butten nothing happen .it should display what i entered.


<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>

</web-app>
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classes ought to be placed in a package. Start with that.
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my name.html form




and this my servlet




there are no pacage statement but still not working?
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aruna sameera wrote:there are no pacage statement but still not working?


That's what Bauke is pointing out. Put your servlet into a package and then change the web.xml to reflect the complete i.e. fully qualified name of the servlet class...
 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had that same problem with my JSP page. It worked when I put my beans in a package.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason is that if the JVM trys to load a class not in a package, it looks in the "current" directory. In the servlet environment you have no control over the "current" directory, therefore ALL classes used in servlets MUST be in packages to avoid strange errors.

Bill
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are environments wherein packageless servlets work (combination of certain appserver implementation/version and certain JVM implementation/version), but you should never make your application dependent on that. Put classes in packages, period. Only then the other classes can import them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic