67,513
社区成员
发帖
与我相关
我的任务
分享
public User findUser(String loginName, String password) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
User user = null;
try {
conn = JDBC_utils.getConnection();
String sql = "select * from user where name=? and password=?";
ps = conn.prepareStatement(sql);
ps.setString(1, loginName);
ps.setString(2, password);
rs = ps.executeQuery();
while (rs.next()) {
user = mappingUser(rs);
}
System.out.println("进行查找");
} catch (SQLException e) {
throw new DaoException(e.getMessage(), e);
} finally {
JDBC_utils.free(rs, ps, conn);
}
return user;
}
User user=new User();
UserDaoImpl udi=new UserDaoImpl();
/* public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
*/
public String execute()
{
if(udi.findUser(user.getName(),user.getPassword())!=null)
return "welcome";
else
return "regist";
}
private User mappingUser(ResultSet rs) throws SQLException {
User user = new User();
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setBirthday(rs.getDate("birthday"));
user.setWorkyear(rs.getFloat("workyear"));
user.setPassword(rs.getString("password"));
return user;
}
package Action;
import jdbc.dao.impl.UserDaoImpl;
import jdbc.user.User;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
User user=new User();
UserDaoImpl udi=new UserDaoImpl();
/* public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
*/
public String execute()
{
if(udi.findUser(user.getName(),user.getPassword())!=null)
return "welcome";
else
return "regist";
}
}
user 的get、set注释掉了,用get、set的时候,也无法查询.
User的代码:package jdbc.user;
import java.util.Date;
//定义了user类
public class User {
private int id;
private String name;
private String password;
private Date birthday;
private float workyear;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public float getWorkyear() {
return workyear;
}
public void setWorkyear(float workyear) {
this.workyear = workyear;
}
}
mysql是连接上的:
返回的信息是:Unexpected Exception caught setting 'denglu' on 'class Action.LoginAction: Error setting expression 'denglu' with value ['??????', ]
十一月 03, 2013 5:08:21 下午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
SEVERE: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'username' on 'class Action.LoginAction: Error setting expression 'username' with value ['lisi', ]
十一月 03, 2013 5:08:21 下午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
SEVERE: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'userpass' on 'class Action.LoginAction: Error setting expression 'userpass' with value ['sd', ]
进行查找
struts中的代码是:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="action" extends="struts-default" >
<!--包的名称 主要供继承者使用 namespace会作为action访问的一部分,简化代码 -->
<action name="LoginAction" class="Action.LoginAction" method="execute">
<result name="welcome">/welcome.jsp</result>
<result name="regist">/regist.jsp</result>
</action>
<action name="RegistAction" class="Action.RegistAction" method="execute">
<result name="success">/Login.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
<!-- Add packages here -->
</struts>