public class User {
Private int id;
Private String username;
Private String password;
Public int getId () {
return id;
}
Public void setId (int id) {
this.id=id;
}
Public String getUsername () {
Return the username.
}
Public void setUsername (String username) {
Enclosing the username=username;
}
Public String getPassword () {
Return the password;
}
Public void setPassword (String password) {
Enclosing the password=password;
}
@ Override
Public String toString () {
Return the User {" + "
"Id=" + id +
"And the username='" + username +' \ ' '+
"And password='" + password +' \ ' '+
'} ';
}
}
public class UserDao {
/* *
* login method
* @ param loginUser only a user name and password
* @ return user contains all user data, there is no query that returns null
*/
//declare JDBCTemplate objects share
Protected the static JdbcTemplate template=new JdbcTemplate (JDBCutil getDataSource ());
/* *
* login method
* @ param loginUser only a user name and password
* @ return user contains all user data, there is no query that returns null
*/
Public static User login (User loginUser) {
Try {
//1. Write SQL
String SQL="select * from the user where the username=? And password=?" ;
//2. Call the query method
User User=template. QueryForObject (SQL,
New BeanPropertyRowMapper(the User. The class),
LoginUser. GetUsername (), loginUser. GetPassword ());
return user;
} the catch (DataAccessException e) {
return null;
}
}
}
/* ** Created by Administrator on 2020/3/16 18:51
* @ author Administrator
*/
//used to landing operation interface
@ WebServlet ("/loginServlet ")
Public class LoginServlet extends the HttpServlet {
@ Override
Protected void doGet (it the req, HttpServletResponse resp) throws ServletException, IOException {
//1. Set the coding
The req. SetCharacterEncoding (" utf-8 ");
//2. Get request parameter
String username=the req. GetParameter (" username ");
String password=the req. GetParameter (" password ");
//3. Wrap the user object
The User loginUser=new User ();
LoginUser. SetUsername (username);
LoginUser. SetPassword (password);
//4. Call UserDao login method
User User=UserDao. Login (loginUser);
//5. Determine the user
If (user==null) {
//login failed
The req. GetRequestDispatcher ("/failServlet "). The forward (the req, resp);
} else {
//login success
//store data
The req. SetAttribute (" user ", the user).
Forward//
The req. GetRequestDispatcher ("/successServlet "). The forward (the req, resp);
}
}
@ Override
Protected void doPost (it the req, HttpServletResponse resp) throws ServletException, IOException {
Enclosing doGet (the req, resp);
}
}
//4. Call UserDao login method
User User=UserDao. Login (loginUser);
When I Debug the code above program will be terminated and error
Java. Lang. ClassNotFoundException: org. Springframework. Dao. DataAccessException
The at org. Apache. Catalina. Loader. WebappClassLoaderBase. LoadClass (WebappClassLoaderBase. Java: 1358)
The at org. Apache. Catalina. Loader. WebappClassLoaderBase. LoadClass (WebappClassLoaderBase. Java: 1180)
At com. Servlet. LoginServlet. DoGet (LoginServlet. Java: 37)
At com. Servlet. LoginServlet. DoPost (LoginServlet. Java: 55)
CodePudding user response:
For what I want to create a accept the object will be an error, I am drunk, a great god answer ahCodePudding user response:
Java. Lang. ClassNotFoundException: org. Springframework. Dao. DataAccessExceptionDon't have to prompt you, not this class
CodePudding user response:
If it is lack of jar, compile should pass theMay be a jar conflicts,
You still replace DataAccessException, with Exception directly
CodePudding user response: