GoogleSearchBox

Custom Search

Tuesday, May 6, 2014

Struts2 action called twice or multiple of times

Struts2 action gets called twice or multiple of times specially when dealing with Json:

I used to get issues while calling Struts2 action using jQuery Ajax and passing JSON to and from Action.

Reason: Struts2 uses a lot interceptors in its default stack to pre and post process the request.
And in particular JSONInterceptor will try to call all the getter methods available  using java Refelection api  inside the Action class (which makes it multiple calls) and tries to serialize the objects returned from the getter methods.

Solution:
     You need to refactor/rename your getter methods with some other meaningful names like loadXXXXX / showXXXX.




Reference:
http://stackoverflow.com/questions/6061709/struts2-action-being-called-twice-if-result-type-is-json


Tags:
struts2 action multiple methods execute
struts2 action  automatically calling many times
struts2 action class automatically calling many times
why my struts2 action class invoke previous execute method
struts2 action calls previous method
struts2 filter mapping calls many methods