如题,我把部分代码贴出来,也比较好说明.
首先定义了USER的BEAN,里面就NAME和AGE 2个STRING字段:
private String name = null;
private String age = null;
====================================================
FORM里对应的LIST是 private List<User> userLst = null;
====================================================
之后JSP上处理是:
a.jsp
<Script Language="javascript">
function selectAction()
{
document.forms(0).action="BAction.do";
document.forms(0).submit();
}
</Script>
<html:form action="/LAction">
<html:submit/>
<logic:notEmpty name="lform" property="userLst">
<table>
<logic:iterate id="lst" name="lform" property="userLst" >
<tr>
<td><html:text name="lst" property="name" indexed="true"/></td>
<td><html:text name="lst" property="age" indexed="true"/></td>
</tr>
</logic:iterate>
<tr>
<td><html:text name="lform" property="id"/></td> <!-- id只是FORM里做测试的东西,发现能传送到B.JSP -->
</tr>
<tr>
<td><html:button property="go" value="go" onclick="selectAction()"/></td>
</tr>
</table>
</logic:notEmpty>
</html:form>
====================================================
b.jsp
<html:form action="/BAction">
<html:submit/>
<logic:notEmpty name="lform" property="userLst">
<table>
<logic:iterate id="lst" name="lform" property="userLst">
<tr>
<td><html:text name="lst" property="name"/></td>
<td><html:text name="lst" property="age"/></td>
</tr>
</logic:iterate>
</table>
</logic:notEmpty>
</html:form>
====================================================
对应的ACTION:
LAction.java
LForm lform = (LForm)form;
List<User> uslst = lform.getUserLst();
if(uslst==null||uslst.size()==0){
User user = new User();
user.setName("name");
user.setAge("age");
uslst = new ArrayList<User>();
uslst.add(user);
lform.setUserLst(uslst);
lform.setId("getme");
}
request.setAttribute("lform", lform); // 设置断点,此时lform里的id和uslst是有值的
return mapping.findForward("a"); //对应跳a.JSP
====================================================
BAction.java
LForm lform = (LForm)form;
String id = lform.getId();// 设置断点,此时lform里的id有值,但uslst =null了.
List<User> uslst = lform.getUserLst();
return mapping.findForward("b"); //对应跳转b.JSP
====================================================
struts-config.xml
<action path="/LAction" type="com.action.LAction" name="lform" scope="request" <!-- 只能用request -->
validate="false" />
<action path="/BAction" type="com.action.BAction" name="lform" scope="request" <!-- 只能用request -->
validate="false" />
====================================================
框架用的是STRUTS1.2,服务器用的是TOMCAT5.5,运行过程中没有错误.
另外JSP中用
<html:hidden name="lst" property="name" indexed="true"/>
之类的也试过,无效.
希望能指教下,怎么才能在BAction中接受到LIST里的值?
首先定义了USER的BEAN,里面就NAME和AGE 2个STRING字段:
private String name = null;
private String age = null;
====================================================
FORM里对应的LIST是 private List<User> userLst = null;
====================================================
之后JSP上处理是:
a.jsp
<Script Language="javascript">
function selectAction()
{
document.forms(0).action="BAction.do";
document.forms(0).submit();
}
</Script>
<html:form action="/LAction">
<html:submit/>
<logic:notEmpty name="lform" property="userLst">
<table>
<logic:iterate id="lst" name="lform" property="userLst" >
<tr>
<td><html:text name="lst" property="name" indexed="true"/></td>
<td><html:text name="lst" property="age" indexed="true"/></td>
</tr>
</logic:iterate>
<tr>
<td><html:text name="lform" property="id"/></td> <!-- id只是FORM里做测试的东西,发现能传送到B.JSP -->
</tr>
<tr>
<td><html:button property="go" value="go" onclick="selectAction()"/></td>
</tr>
</table>
</logic:notEmpty>
</html:form>
====================================================
b.jsp
<html:form action="/BAction">
<html:submit/>
<logic:notEmpty name="lform" property="userLst">
<table>
<logic:iterate id="lst" name="lform" property="userLst">
<tr>
<td><html:text name="lst" property="name"/></td>
<td><html:text name="lst" property="age"/></td>
</tr>
</logic:iterate>
</table>
</logic:notEmpty>
</html:form>
====================================================
对应的ACTION:
LAction.java
LForm lform = (LForm)form;
List<User> uslst = lform.getUserLst();
if(uslst==null||uslst.size()==0){
User user = new User();
user.setName("name");
user.setAge("age");
uslst = new ArrayList<User>();
uslst.add(user);
lform.setUserLst(uslst);
lform.setId("getme");
}
request.setAttribute("lform", lform); // 设置断点,此时lform里的id和uslst是有值的
return mapping.findForward("a"); //对应跳a.JSP
====================================================
BAction.java
LForm lform = (LForm)form;
String id = lform.getId();// 设置断点,此时lform里的id有值,但uslst =null了.
List<User> uslst = lform.getUserLst();
return mapping.findForward("b"); //对应跳转b.JSP
====================================================
struts-config.xml
<action path="/LAction" type="com.action.LAction" name="lform" scope="request" <!-- 只能用request -->
validate="false" />
<action path="/BAction" type="com.action.BAction" name="lform" scope="request" <!-- 只能用request -->
validate="false" />
====================================================
框架用的是STRUTS1.2,服务器用的是TOMCAT5.5,运行过程中没有错误.
另外JSP中用
<html:hidden name="lst" property="name" indexed="true"/>
之类的也试过,无效.
希望能指教下,怎么才能在BAction中接受到LIST里的值?
解决方案 »
- SSH整合出问题:java.lang.OutOfMemoryError: Java heap space
- 现在有几个问题,有知道的告诉下 谢谢大家了,等高手!!
- 关于将直角框改成圆角框的问题
- JavaBean的奇怪问题
- jsf很郁闷的问题
- 很难解决的的一个问题!!!软件测试没学好啊
- 请问大家一个问题,我如何在点IE的刷新按钮后跳转到别的页面!
- 请问一下:现在公司招聘程序员有年龄限制吗?
- 我想找一个经济实用支持Tomcat+mysql+jsp的主机,谁知道?
- 求助谁有“实现将一则信息发布到网上的功能”的纯JSP实例,小妹急需!给分哟!
- 求救:jsp 加载servlet文件时出错。
- java插入数据时为什么有时能执行到触发器,有时又不行
那样b的Action就能获得a的Action赋的值。
也就是说,从a.jsp先到a的Action再到b的Action,就OK了。
不知楼主明白么。