Action使用ModelDriven<User>,在jsp页面获取到的user对象的数据是null? 50
publicclassUserActionextendsBaseActionimplementsModelDriven<User>{privateUseruser=new...
public class UserAction extends BaseAction implements ModelDriven<User>{
private User user = new User();
UserDAO dao = new UserDAOImpl();
public User getModel() {
return user;
}
public String login(){
user = dao.findByName(user.getName());
if(user != null){
session.put("user", user);
return "success";
}
return "fail";
}
}
--------------------
<form action="add.action" method="post">
id:<input type="text" name="id" value="<s:property value="id" />"><br>
name:<input type="text" name="name" value="<s:property value="name" />"><br>
pwd:<input type="text" name="pwd" value="<s:property value="pwd" />"><br>
<s:textfield name="id"></s:textfield><br>
<s:textfield name="name"></s:textfield><br>
<s:textfield name="pwd"></s:textfield><br>
<input type="submit" value="submit">
</form> 展开
private User user = new User();
UserDAO dao = new UserDAOImpl();
public User getModel() {
return user;
}
public String login(){
user = dao.findByName(user.getName());
if(user != null){
session.put("user", user);
return "success";
}
return "fail";
}
}
--------------------
<form action="add.action" method="post">
id:<input type="text" name="id" value="<s:property value="id" />"><br>
name:<input type="text" name="name" value="<s:property value="name" />"><br>
pwd:<input type="text" name="pwd" value="<s:property value="pwd" />"><br>
<s:textfield name="id"></s:textfield><br>
<s:textfield name="name"></s:textfield><br>
<s:textfield name="pwd"></s:textfield><br>
<input type="submit" value="submit">
</form> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询