public class AdminAction extends ActionSupport implements RequestAware {
private int id;
private String username;
private String password;
private Admin admin;
private AdminService adService = new AdminService();
private List admins = null;
private Map<String,Object> request;
/**
* @return the id
*/
private int getId() {
return id;
}
/**
* @param id the id to set
*/
private void setId(int id) {
this.id = id;
}
/**
* @return the admins
*/
private List getAdmins() {
return admins;
}
/**
* @param admins the admins to set
*/
private void setAdmins(List admins) {
this.admins = admins;
}
/**
* @return the username
*/
private String getUsername() {
return username;
}
/**
* @param username
* the username to set
*/
private void setUsername(String username) {
this.username = username;
}
/**
* @return the password
*/
private String getPassword() {
return password;
}
/**
* @param password
* the password to set
*/
private void setPassword(String password) {
this.password = password;
}
/**
* @return the admin
*/
private Admin getAdmin() {
return admin;
}
/**
* @param admin
* the admin to set
*/
private void setAdmin(Admin admin) {
this.admin = admin;
}
public String add() {
if (!getUsername().equals(null) && !getPassword().equals(null)) {
adService.save(admin);
return "addSuccess";
} else {
return "error";
}
}
public String edit(){
if (!getUsername().equals(null) && !getPassword().equals(null)) {
adService.update(admin);
return "editSuccess";
} else {
return "error";
}
}
public String list() {
admin = new Admin();
//admins = new ArrayList<Admin>();
admins = adService.query();
//通过session方式输出
//ActionContext.getContext().getSession().put("admins",admins);
if(admins.size()>0){
return "list";
}else{
return "error";
}
}
public String remove(){
if (!getUsername().equals(null) && !getPassword().equals(null)) {
adService.delete(admin);
return "deleteSuccess";
} else {
return "error";
}
}
@Override
public void setRequest(Map<String, Object> request) {
this.request = request;
}
}
页面 <s:iterator value="admins" id="admin" >
<tr>
<td>
${admin.password }
</td>
<td>
<s:property value="admins.passwrod"/>
</td>
<td><s:url id="url" action="getuser!add">ADD</s:url></td>
<td><s:url id="url" action="getuser!edit">Edit</s:url></td>
<td><s:url id="url" action="getuser!remove">DEL</s:url></td>
</tr>
</s:iterator>
最后终于在整理思路的时候解决了。在JSP页面与ACTION之间的桥梁对于程序员来说就是set get方法以及valueStack,既然对方始终获取不了值,那么要么是valueStack有问题(这个框架的东东应该不会错),那就是set get 方法的问题。最后找到使用自动生成set get方法的权限由问题。private 将其更改为public 搞定!!!还是谢谢各位热心帮忙!!
但是不使用session传,直接获取admins始终不成功!
追答这么传值本来就有2种方法 一种是session 一种就是通过struts2的机制来传,你可能使用的第二种方式 第一种也可以 如果你想知道的话 咱们在说
本回答被提问者采纳