Struts2+ Spring : Request Paremeters dont get reset in Action objects?
我正在开发Spring 3 Struts2应用程序,并在Spring中配置我的Action如下:
1 2 3 | <bean id="patientSearchAPIClass" class="com.axiohelix.nozoki.web.action.api.PatientSearch"> <property name="searchService" ref="searchService"/> </bean> |
但是在我的Action类中,我保留了一些字段来存储Request参数,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | public class PatientSearch extends ActionSupport { public String getPharumoId() { return pharumoId; } public void setPharumoId(String pharumoId) { this.pharumoId = pharumoId; } public String getName() { return name; } public void setName(String name) { this.name = name; } private String name; private String pharumoId; .. public String execute(){ searchResults=searchService.searchPatients(pharumoId, name, birthday, pharmacyId, clinic, doctorName, drugName, supplyDate, offset, pageSize); return Action.SUCCESS; } |
此操作返回JSON输出,我使用如下网址访问它:
http://localhost/app/searchAPI.action?name = UserName
然后下一次,如果我使用URL访问:
http://localhost/app/searchAPI.action
字段"名称"一直设置为先前的"用户名"值。
1。如何根据请求重置这些值?
2。我认为Action类是按请求实例化的,不是吗?
问题在于Spring创建Action类的方式。默认情况下,Spring创建单例实例,对于Struts2,Action类也可以作为Model使用,因为此框架创建了Action的新实例并将其放入值堆栈中。
在使用Spring创建动作类时,请确保将作用域定义为原型,例如
1 2 | <bean id="patientSearchAPIClass" class="com.axiohelix.nozoki.web.action.api.PatientSearch" scope=prototype> |
因此,Spring应为每个请求创建Action的新实例。