我會嘗試儘可能具體。獲取json返回類型和html返回相同的動作
我有一個Action有兩個方法,一個是通過ajax調用,另一個是通過常規提交調用。
重點是無法從常規提交中獲取請求,我只獲取操作屬性。
public class ClientAction{
@SMDMethod
public Map<String, Object> findClient(String myParam){
...
}
public String saveClient(){
Map<String, String[]> parameterMap = this.getRequest().getParameterMap();
}
}
getRequest from saveClient方法返回null !!!但爲什麼???我沒有@SMDMethod
聲明它和這裏是struts.xml中
<action name="client" class="myCompany.ClientAction">
<interceptor-ref name="customJSON"><param name="enableSMD">true</param></interceptor-ref>
<result type="json"><param name="enableSMD">true</param></result>
</action>
我做了所有的其他聲明。我曾經有兩個單獨的類,每個方法都有一個,但ClientAction和ClientActionJSON的可維護性並不容易。
有關如何在同一個類中同時使用兩種方法(一種ajax和其他方法)的任何想法。
使用_action_批註,並使用嵌套的_result_批註指定結果類型。 XML也是一樣的。當然,這將兩個動作放到一個類中......語義的輕微改變,在這種情況下不需要「enableSMD」。我想你可能需要在struts2-conventions-plugin(我總是添加它,所以不確定)。 – Quaternion
你的意思是這樣的嗎? true interceptor-ref> 真 '和另外一個像'<動作名稱=」 客戶」類= 「myCompany.ClientAction」>' –
Sergio1978
你還在使用enableSMD使之不我的意思是... – Quaternion