【发布时间】:2012-08-17 15:14:33
【问题描述】:
我正在开发 Spring 3 + Struts2 应用程序,我在 Spring 中配置我的操作如下:
<bean id="patientSearchAPIClass" class="com.axiohelix.nozoki.web.action.api.PatientSearch">
<property name="searchService" ref="searchService"/>
</bean>
但在我的 Action 类中,我保留字段来存储请求参数,
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 输出,我使用以下 URL 访问它:
http://localhost/app/searchAPI.action?name=UserName
如果我下次使用 URL 访问:
http://localhost/app/searchAPI.action
“名称”字段设置为之前的“用户名”值。
1.如何根据请求重置这些值?
2.我认为 Action 类是根据请求实例化的,不是吗?
【问题讨论】:
-
如果是,你是否在使用 struts2-spring 插件,将 bean 范围更改为
prototype因为默认情况下它的单例和 S2 也使用 Action 作为数据传输对象。就像<bean id="patientSearchAPIClass" class="com.axiohelix.nozoki.web.action.api.PatientSearch" scope=prototype> -
是的,我正在使用 struct2-spring 插件。感谢您的提示。让我试试吧。
-
@UmeshAwasthi 谢谢它的工作。你能把这个作为答案发布,以便我可以选择它作为正确的。
标签: java spring struts2 httprequest