Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java com.mysql.jdbc.Driver无法为JSP编译_Java_Jsp - Fatal编程技术网

Java com.mysql.jdbc.Driver无法为JSP编译

Java com.mysql.jdbc.Driver无法为JSP编译,java,jsp,Java,Jsp,我正在尝试使用JSP创建登录系统并连接到MySQL数据库,但出现以下错误: 我的代码: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="com.core.bibit.service.Security" import="javax.servlet.*" import="java.util.*" import="com.mysql.jdbc.Driver"

我正在尝试使用JSP创建登录系统并连接到MySQL数据库,但出现以下错误:

我的代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
import="com.core.bibit.service.Security"
import="javax.servlet.*"
import="java.util.*"
import="com.mysql.jdbc.Driver"
%>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");

boolean test = new Security().validateUser(username, password);
System.out.println("Authen: " + test);
if(test){
    response.sendRedirect("test.jsp");
}else{
    response.sendRedirect("about.jsp");
} 
%>
我使用TomEE/Tomcat 7.0,我的MySQL库是:MySQL-connector-java-5.1,我尝试将其添加到server.xml文件中:

<Resource name="jdbc/DATABASENAME" type="javax.sql.DataSource" maxActive="4" maxIdle="2"    username="root" password="" maxWait="23000" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:8889/bibit"></Resource>

有人能解释什么是错误的,或者如何修复它,或者只是朝着正确的方向推动一下吗


解决方案:如果通过Eclipse启动服务器并在一行中导入文件,则通过Eclipse添加mysql连接器,如下所示

例如,您需要使用逗号分隔的导入列表

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="com.core.bibit.service.Security, javax.servlet.*,java.util.*, com.mysql.jdbc.Driver"%>


并确保您在类路径中有所需的JAR/类(在运行时也是如此)

您的JSP代码不需要所有这些导入,除了
安全性
类,请删除所有其他导入

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="com.core.bibit.service.Security" %> //only Security class is needed
尝试建立与给定数据库URL的连接。
DriverManager
尝试从注册的JDBC驱动程序集中选择适当的驱动程序

参数:

  • url-数据库url的形式为jdbc:subtocol:subname
  • user—代表其进行连接的数据库用户
  • 密码-用户的密码

确保所有必需的jar都在类路径中

很可能JDBC驱动程序jar不在web应用程序的类路径中;首先检查那里。你把驱动器jar文件复制到/lib文件夹了吗?!顺便问一下,你为什么不使用连接池?!而且你也没有关闭连接!这将导致dude.user251414连接池?的灾难,驱动程序jar否我被告知我不应该这么做这两个答案都有帮助,但我现在得到了这个错误:java.sql.SQLException:找不到适合jdbc的驱动程序:mysql://localhost:8889/bibit@拉斯尼尔森:更改url
jdbc:mysql://localhost:3306/bibit
。3306是mysql的默认端口,但我的服务器运行在8889上,这是服务器mysql还是tomcat?安装时是否配置了mysql服务器端口?用粗体解决方案在quesito中写道。无论如何,我已经将MySQL连接器添加到apache服务器上的Lib中,但这不起作用,所以我尝试通过eclipse来实现,它起作用了,并将所有导入移到一行
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="com.core.bibit.service.Security" %> //only Security class is needed
public static Connection getConnection(String url, 
                                       String user, 
                                       String password) throws SQLException