当前位置: 代码迷 >> Java Web开发 >> ssh 参数传递值总为null解决办法
  详细解决方案

ssh 参数传递值总为null解决办法

热度:804   发布时间:2016-04-15 22:42:48.0
ssh 参数传递值总为null
action代码
@Controller("userAction")     @Transactional
public class UserAction extends ActionSupport{
@Resource private UserService userService;
private Integer  id;
private String username;
private String password;
private String verifycode;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getVerifycode() {
return verifycode;
}
public void setVerifycode(String verifycode) {
this.verifycode = verifycode;
}
public String execute(){
User user=new User();
System.out.println(id);
System.out.println(username);
System.out.println(password);
user.setUsername(username);
user.setPassword(password);
boolean flag=userService.findUser(user);
if(flag){
ActionContext.getContext().put("user", user);
return "login";
}
else{
ActionContext.getContext().put("message", "用户名或密码错误");
return "relogin";
}
}
}

set/get方法都有 页面name和字段名也对上了。郁闷新手求指教
------解决思路----------------------
你先看看'请求调用action了没有''
------解决思路----------------------
没找到错,你试试实现模型驱动:
action代码
@Controller("userAction")     @Transactional
public class UserAction extends ActionSupport implements ModelDriven<User>{
@Resource private UserService userService;
///////////////////////////////////////////////////////////////////////////////////////
User u=new User();
 @Override  
public User  getModel() {  
   return u;
}
//////////////////////////////////////////////////////////////////////////////////////////
public String execute(){

System.out.println(u.getId);
System.out.println(u.getUsername);
System.out.println(u.getPassword);

boolean flag=userService.findUser(u);
if(flag){
ActionContext.getContext().put("user", user);
return "login";
}
else{
ActionContext.getContext().put("message", "用户名或密码错误");
return "relogin";
}
}
}
  相关解决方案