今天在运行Struts2时,无意间发现程序在写Struts.xml有这样的问题:
以下是本人一个Action映射的配置文件
xml 代码
- <action name="saveExhibitionAppTable"
- class="cn.gov.tdb.controller.EnterpriseController"
- method="saveExhibitionAppTable">
- <result name="input">exhibitionAppTable.jspresult>
- <result name="success" type="redirect-action">
- generateBarcode.tdbdb?getTichetSource=${getTichetSource}&companyId=${companyId}&serviceId=${serviceId}
- result>
- action>
没有什么特别的地方就是在
xml 代码
- <result name="success" type="redirect-action">
- generateBarcode.tdbdb?getTichetSource=${getTichetSource}&companyId=${companyId}&serviceId=${serviceId}
- result>
这里返回的是一个redirect-action, ${getTicketSource}等这三个参数是这个Action的三个
属性(有get,set方法的),我想把它们传给generateBarcode.tdbdb, 却发现一直取不到这
三个传过来的参数,空指针报错.
然后我又把配置文件改成如下,弄成generateBarcode.jsp发现值确实已经传过来了,看来Struts2在redirec-action的时候已经处理过了.
xml 代码
- <result name="success">
- generateBarcode.jsp?getTichetSource=${getTichetSource}&companyId=${companyId}&serviceId=${serviceId}
- result>
查了查Strut2的文档,发现有以下配置,也就是说这个时候把要传递的参数如果分开来的话,通过redirec-action也是可以正常传过来的.
xml 代码
- <action name="saveExhibitionAppTable"
- class="cn.gov.tdb.controller.EnterpriseController"
- method="saveExhibitionAppTable">
- <result name="input">exhibitionAppTable.jspresult>
- <result name="success" type="redirect-action">
- <param name="actionName">generateBarcodeparam>
- <param name="namespace">/param>
- <param name="getTichetSource">${getTichetSource}param>
- <param name="companyId">${companyId}param>
- <param name="serviceId">${serviceId}param>
- result>
- action>
大家注意过这个问题吗?