参数不从 HTML 表单传递到 MySQL(通过 Tomcat、Eclipse(IDE)、Servlet 和 Java Bean) [英] Parameters not passing from HTML form to MySQL (via Tomcat, Eclipse(IDE), Servlet, and Java Bean)

查看:57
本文介绍了参数不从 HTML 表单传递到 MySQL(通过 Tomcat、Eclipse(IDE)、Servlet 和 Java Bean)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个用于学习目的的小型 Web 应用程序,使用 Apache Tomcat、Eclipse、Java EE(Servlet、JSP、Bean)、MySql 数据库作为后端.我已将 Eclipse 配置为包含 Tomcat、MySql 连接器.

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.

项目:

  1. 用于输入用户名、电子邮件和密码的 HTML 表单.
  2. 用于将参数传递给 Java Bean 的 Servlet.
  3. Java Bean 将参数传递给 MySql 数据库.

工作原理:当 Java Bean 没有连接到数据库 using(return 语句)时,应用程序运行.

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

什么不起作用:当我在 Java Bean 中使用数据库连接时,应用程序不起作用.并且MySql数据库没有参数更新.

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.

我所做的:我检查了数据库连接性,它与单个 Java Class 文件一起工作正常,并且可以将参数传递给 MySql 数据库.

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.

我认为我的 Web 应用程序中存在一些问题,而不是与数据库的连接.那么有人可以建议我应该做什么吗?

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

推荐答案

我在服务器上运行 Web 应用程序时遇到此异常:出现异常!com.mysql.jdbc.Driver

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

尽管异常处理很差(异常类型完全缺失),异常消息com.mysql.jdbc.Driver 是典型的ClassNotFoundException.这是不言自明的:运行时类路径中缺少该类或至少包含该类的 JAR 文件.

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.

要解决此问题,您只需将 MySQL JDBC 驱动程序 JAR 文件放在类路径中.如果您不方便容器管理的 JNDI 数据源,只需将 JAR 文件放在 webapp 的 /WEB-INF/lib 文件夹中就足够了.但是,如果您正在使用 JNDI 数据源(强烈推荐,提供连接池,更好的性能),那么您需要将 JAR 文件放在 servletcontainer 的类路径中.在 Tomcat 中,这将是它的 /lib 文件夹.

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());
}

而是抛出至少e.printStackTrace().

这篇关于参数不从 HTML 表单传递到 MySQL(通过 Tomcat、Eclipse(IDE)、Servlet 和 Java Bean)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆