共计 893 个字符,预计需要花费 3 分钟才能阅读完成。
我想实现的是根据班级获取学生信息,首先select标签动态获取班级列表,选择后然后提交给action,但是一直得不到值,再三寻找最终找到了解决方法
<s:form action=”findUserByDep.action”>
<s:select label=”请选择班级” list=”list” listKey=”depId” listValue=”depName” name=”depInfo”></s:select>
<s:submit value=”提交”></s:submit>
</s:form>
这是select标签的代码,记住name是depInfo。
public class UserAction extends ActionSupport {
private List list2;
User user = new User();
private String depInfo;
public String getDepInfo() {
return depInfo;
}
public void setDepInfo(String depInfo) {
this.depInfo = depInfo;
}
public List getList2() {
return list2;
}
public void setList2(List list2) {
this.list2 = list2;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String listUser() {
UserDao dao = new UserDao();
list2 = dao.listUser();
return “success”;
}
public String findUserByDep() {
UserDao dao = new UserDao();
list2 = dao.findUserByDep(getDepInfo());
return “success”;
}
这是action的代码,首先定义了depInfo,生成getter和setter,最终select的key值就可以用getDeoInfo()来获取,