简体   繁体   中英

Parameters not passing from HTML form to MySQL (via Tomcat, Eclipse(IDE), Servlet, and Java Bean)

I am designing a small web application for learning purpose using Apache Tomcat, Eclipse, Java EE (Servlet, JSP, Bean), MySql Database as backend. I have configured Eclipse to include Tomcat, MySql connector.

The Project:

  1. A HTML form for entering UserName, Email, and Password.
  2. Servlet for passing parameter to Java Bean.
  3. Java Bean to passing parameter to MySql database.

What's Working: The application runs when the Java Bean has no connectivity to database using (return statement).

What's not working: The application does not work when I use database connectivity in Java Bean. And the MySql database is not updated with parameters.

What I did: I checked with database connectivity it's working fine with individual Java Class files and it can pass parameters to MySql database.

I think there is some problem in my Web Application and not connectivity with database. So can anyone suggest what i should do?

I am getting this Exception while running the web application on server: Got an exception! com.mysql.jdbc.Driver

Although the exception handling is poor (exception type is completely missing), the exception message com.mysql.jdbc.Driver is typical for a ClassNotFoundException . This is pretty self-explaining: the class or at least the JAR file containing the class is missing in the runtime classpath.

To fix this, all you need to do is to put the MySQL JDBC driver JAR file in the classpath. If you aren't faciliting the container managed JNDI datasource, just dropping the JAR file in webapp's /WEB-INF/lib folder is sufficient. But if you're utilizing a JNDI datasource (strongly recomment, offers connection pooling, better performance), then you need to drop the JAR file in servletcontainer's classpath. In Tomcat, that would be its /lib folder.

That said, please improve your exception handling. Don't do a nothing-saying

} catch (Exception e) {
    System.out.println("Got an exception! " + e.getMessage());
}

but rather throw it through or do at least e.printStackTrace() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM