简体   繁体   English

Eclipse中struts2 mysql的连接错误

[英]struts2 mysql conection error in eclipse

I am connecting to MySQL using JDBC to the JSP, but it shows error classNotFoundException in eclipse in struts JSP page. 我正在使用JDBC到JSP的MySQL连接到MySQL,但是它在struts JSP页面的eclipse中显示了错误classNotFoundException

validate.java: validate.java:

package com.demo;
import java.sql.*;  
public class LoginValidate {

    public boolean validateLogin(){
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/inspioqj_appointment");
        return true;    
    }
}

Same code using in same project jsp file its working what is problem i am not understanding. 在同一项目的jsp文件中使用相同的代码,其工作是我不了解的问题。

index.jsp: index.jsp:

<%@ page language="java" import="java.sql.*" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p> There is home page.</p>
<hr/>  
<a href="login">login</a>|  
<a href="logout">logout</a>|  
<a href="profile">profile</a> 
<%

Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/inspioqj_appointment");
%>
</body>
</html>

I have included MySQL java connector on lib folder in eclipse struts project, but it is not working in action controller validate.java but it is working in index.jsp page. 我在eclipse struts项目的lib文件夹中包含了MySQL java连接器,但是它在动作控制器validate.java 不起作用,但在index.jsp页面中起作用。

What is problem? 怎么了 I could not understand. 我听不懂

Its a pretty simple ClassNotFoundException. 它是一个非常简单的ClassNotFoundException。 Make sure that the mySQL jar is present in the class-path of the project as well. 确保项目的类路径中也存在mySQL jar。 You can do this by right-clicking the project, configure class-path and from there you can add the particular jar 您可以通过右键单击项目,配置类路径来执行此操作,然后从那里可以添加特定的jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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