提示Cannot make a static reference to the non-static method
参照另一个项目写的注册Action里:
//struts2
package com.softeem.action;
import com.opensymphony.xwork2.ActionSupport;
import com.softeem.pojo.User;
import com.softeem.service.UserService;
public class RegistAction extends ActionSupport{
private String username;
private String password;
private UserService userservice;
private String tip;
public String getTip() {
return tip;
}
public void setTip(String tip) {
this.tip = tip;
}
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 UserService getUserservice() {
return userservice;
}
public void setUserservice(UserService userservice) {
this.userservice = userservice;
}
public String execute() throws Exception {
if(UserService.saveUser(getUsername(), getPassword())){ //
错误信息就在这里
setTip("注册成功");
return "success";
}
else
return "error";
}
}
然后又不能去吧Userservice里的saveUser变成static,请问是哪里出了问题?
------解决方案--------------------getUsername(), getPassword())直接写username和passsword就可以了
struts将servlet封装,有set和get方法即可拿到你输入的值