Home > Back-end >  Why I login interface for the information, when I create a UserDao object will be terminated, no lon
Why I login interface for the information, when I create a UserDao object will be terminated, no lon

Time:10-06

 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 ah

CodePudding user response:

Java. Lang. ClassNotFoundException: org. Springframework. Dao. DataAccessException
Don't have to prompt you, not this class

CodePudding user response:

If it is lack of jar, compile should pass the
May be a jar conflicts,
You still replace DataAccessException, with Exception directly

CodePudding user response:

refer to the second floor from the underlying program apes looked response:
Java lang. ClassNotFoundException: org. Springframework. Dao. DataAccessException
Don't have to prompt you, don't have the class

I guide the JDBC package

CodePudding user response:

I feel there is no dependency injection!!!! Or structural parameters, the set, annotation and new objects, I see you what all not directly define a static method call

CodePudding user response:

You quoted the wrong class, it is to belong to the spring - tx - 4.3.8. The jar
You look at your project whether to have this package, the version number does not agree it doesn't matter
If there is no import, also can be like 3 l said, with the Exception capture
  • Related