---
title: "Struts2需要注意的一个小地方"
author: "kyo100900"
date: "2007-10-22T17:49:26Z"
tags: []
categories: ["非技术"]
slug: "struts2"
draft: false
lastmod: "2007-10-22T17:49:26Z"
id: 134505
url: "https://superleo.iteye.com/blog/134505"
---

**今天在运行Struts2时,无意间发现程序在写Struts.xml有这样的问题:**

**以下是本人一个Action映射的配置文件**

xml 代码

1. &lt;action name="saveExhibitionAppTable"
2. class="cn.gov.tdb.controller.EnterpriseController"
3. method="saveExhibitionAppTable"&gt;
4. &lt;result name="input"&gt;exhibitionAppTable.jspresult&gt;
5. &lt;result name="success" type="redirect-action"&gt;
6. generateBarcode.tdbdb?getTichetSource=${getTichetSource}&companyId=${companyId}&serviceId=${serviceId}
7. result&gt;
8. action&gt;

 

**没有什么特别的地方就是在**

xml 代码

1. &lt;result name="success" type="redirect-action"&gt;
2. generateBarcode.tdbdb?getTichetSource=${getTichetSource}&companyId=${companyId}&serviceId=${serviceId}
3. result&gt;

这里返回的是一个redirect-action, ${getTicketSource}等这三个参数是这个Action的三个属性(有get,set方法的),我想把它们传给generateBarcode.tdbdb, 却发现一直取不到这三个传过来的参数,空指针报错.

然后我又把配置文件改成如下,弄成generateBarcode.jsp发现值确实已经传过来了,看来Struts2在redirec-action的时候已经处理过了.

xml 代码

1. &lt;result name="success"&gt;
2. generateBarcode.jsp?getTichetSource=${getTichetSource}&companyId=${companyId}&serviceId=${serviceId}
3. result&gt;

查了查Strut2的文档,发现有以下配置,也就是说这个时候把要传递的参数如果分开来的话,通过redirec-action也是可以正常传过来的.

xml 代码

01. &lt;action name="saveExhibitionAppTable"
02. class="cn.gov.tdb.controller.EnterpriseController"
03. method="saveExhibitionAppTable"&gt;
04. &lt;result name="input"&gt;exhibitionAppTable.jspresult&gt;
05. &lt;result name="success" type="redirect-action"&gt;
06. &lt;param name="actionName"&gt;generateBarcodeparam&gt;
07. &lt;param name="namespace"&gt;/param&gt;
08. &lt;param name="getTichetSource"&gt;${getTichetSource}param&gt;
09. &lt;param name="companyId"&gt;${companyId}param&gt;
10. &lt;param name="serviceId"&gt;${serviceId}param&gt;
11. result&gt;
12. action&gt;

 

**大家注意过这个问题吗?**