psmt.setString(1, user.getUsername());
psmt.setString(2, user.getPassword());
int a=psmt.executeUpdate();
if(a>0)
{
System.out.println(user.getUsername()+"第2222次");
System.out.println(user.getPassword()+"第2222次");
return SUCCESS;
}
else
{
return ERROR;
}
} catch (SQLException e) {
e.printStackTrace();
return ERROR;
}
finally
{
if(con != null){
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(psmt != null){
try {
psmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(rs != null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
@Override
public String execute() {
System.out.println(user.getUsername()+"1111");
System.out.println(user.getPassword()+"1111");
UserDAO dao=new UserDAO();
con=dao.getConnection();
try {
psmt =con.prepareStatement("select * from userinfo where username= and password= ");
psmt.setString(1, user.getUsername());
psmt.setString(2, user.getPassword());
rs=psmt.executeQuery();
if(rs.next())
{
System.out.println(user.getUsername()+"第2222次");
System.out.println(user.getPassword()+"第2222次");
return SUCCESS;
}
else
{
return ERROR;
}
} catch (SQLException e) {
e.printStackTrace();
return ERROR;
}
finally
{
if(con != null){
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(psmt != null){
try {
psmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(rs != null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
public User getModel() {
// TODO Auto-generated method stub
return user;
}
}
Struts.xml
[html] < xml version="1.0" encoding="UTF-8" >
http://struts.apache.org/dtds/struts-2.1.dtd">
< xml version="1.0" encoding="UTF-8" >
http://struts.apache.org/dtds/struts-2.1.dtd">
注意:
1、
[html]
中 loginAction 与login. JSP 页面中的
2、
中 regAction与 reg.JSP 页面中的
3、
loginAction 类中 public String Login() 方法 必须在 Struts.xml 中声明