Я пытаюсь реализовать http://code.google.com/p/struts2-jquery/wiki/SelectTag#A_simple_Doubleselect_with_Topics, но я не могу успешно объединить json-перехватчик с другими перехватчиками.
В моем Struts.xml:
<package name="admin" namespace="/admin" extends="struts-default,json-default">
<action name="LoadLists" method="loadLists" class="test.JSONAction">
<interceptor-ref name="json">
<param name="contentType">application/json</param>
<!--interceptor added to override this property below-->
<param name="excludeNullProperties">true</param>
</interceptor-ref>
<result name="success" type="json"/>
<interceptor-ref name="servletConfig"/>
</action>
</package>
Вот некоторые из кодов классов действий.
Обратите внимание, что мне нужна переменная session
, и поэтому я добавил строку <interceptor-ref name="servletConfig"/>
выше, чтобы установить переменную сеанса, чтобы ее можно было использовать в следующем коде Java:
public String loadLists() {
items = (List<String>) session.get("itemsList");
if (itemSelected.equals...
// Do stuff to process the list and generate the second list...
}
public void setItemSelected(String itemSelected) {
this.itemSelected = itemSelected;
}
НО, когда у меня <interceptor-ref name="servletConfig"/>
, журналы ошибок показывают:
org.apache.struts2.json.JSONInterceptor.debug:68 - Content type must be 'application/json' or 'application/json-rpc'. Ignoring request with content type application/x-www-form-urlencoded
и переменная itemSelected
никогда не устанавливается, потому что сериализация json игнорируется!
Если я удаляю <interceptor-ref name="servletConfig"/>
тогда я не могу получить доступ к сеансу!
Что мне не хватает?