I'll straight away consider to write a sample :
<action name="xclient" class="myCompany.ClientAction" method="jsonMethod">
<result type="json"></result>
</action>
<action name="yclient" class="myCompany.ClientAction" method="htmlMethod">
<result type="dispatcher">/pages/y.jsp</result>
</action>
now simply create both methods jsonMethod() & htmlMethod() in your ClientAction, one handling json and another html response.
[EDIT]
I read it again and seems like you require only one-action, well then simply consider using a field (request parameter) to decide the return type.
public String execute(){
//..Other code
if(returntype.equals("json")){
return "jsonresult";
}
else{
return "htmlresult";
}
}
<action name="client" class="myCompany.ClientAction" method="jsonMethod">
<result name="jsonresult" type="json"></result>
<result name="htmlresult" type="dispatcher">/pages/y.jsp</result>
</action>
Above I assumed, returntype
is a String variable which you sent along with each request specifying what return is expected. You can simply send it hidden in the form-submit and set it in the ajax-request.