struts2:action传值给jsp失败(什么也没显示),jsp传值给action却成功 setter和getter都有 10
<s:iteratorvalue="aList"id="aut"><tr><td><s:propertyvalue="#aut.id"/></td><td><s:prop...
<s:iterator value="aList" id="aut">
<tr>
<td ><s:property value="#aut.id" /> </td>
<td ><s:property value="#aut.authority" /> </td>
</tr>
</s:iterator>
loginAction
public class loginAction extends ActionSupport{
AuthorityFactory Factory = new AuthorityFactory();
AuthorityDAO authorityDAO = AuthorityFactory.getAuthorityInstance();
private Authority aut;
private List<Authority> aList = new ArrayList<Authority>();
private String userName;
private String password;
public Authority getAut() {
return aut;
}
public void setAut(Authority aut) {
this.aut = aut;
}
public List<Authority> getAList() {
return aList;
}
public void setAList(List<Authority> aList) {
this.aList = aList;
}
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 execute() throws Exception {
if(userName.equals("123") && password.equals("123"))
return "good";
else
return "bad";
}
public String test() throws Exception{
aList = authorityDAO.findAll();
userName = "12346";
if(!aList.isEmpty()){
return "good";
}
else
return "bad";
}
}
struts.xml:
<action name="log" class="hfut.action.loginAction" method="test">
<result name="good" type="redirect">/jsp/test2.jsp</result>
<result name="bad">/jsp/add.jsp</result>
</action>
jsp:
<form action="log" method="post">
姓名:<input type="text" name="userName" value="123" /><br>
密码:<input type="text" name="password" value="123" /><br>
<input type="submit" value="submit" />
</form> 展开
<tr>
<td ><s:property value="#aut.id" /> </td>
<td ><s:property value="#aut.authority" /> </td>
</tr>
</s:iterator>
loginAction
public class loginAction extends ActionSupport{
AuthorityFactory Factory = new AuthorityFactory();
AuthorityDAO authorityDAO = AuthorityFactory.getAuthorityInstance();
private Authority aut;
private List<Authority> aList = new ArrayList<Authority>();
private String userName;
private String password;
public Authority getAut() {
return aut;
}
public void setAut(Authority aut) {
this.aut = aut;
}
public List<Authority> getAList() {
return aList;
}
public void setAList(List<Authority> aList) {
this.aList = aList;
}
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 execute() throws Exception {
if(userName.equals("123") && password.equals("123"))
return "good";
else
return "bad";
}
public String test() throws Exception{
aList = authorityDAO.findAll();
userName = "12346";
if(!aList.isEmpty()){
return "good";
}
else
return "bad";
}
}
struts.xml:
<action name="log" class="hfut.action.loginAction" method="test">
<result name="good" type="redirect">/jsp/test2.jsp</result>
<result name="bad">/jsp/add.jsp</result>
</action>
jsp:
<form action="log" method="post">
姓名:<input type="text" name="userName" value="123" /><br>
密码:<input type="text" name="password" value="123" /><br>
<input type="submit" value="submit" />
</form> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询