struts2 ajax exception

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.StrutsStatics;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class AjaxExceptionInteceptor extends AbstractInterceptor {

/**
*
*/
private static final long serialVersionUID = 1L;

@Override
public String intercept(ActionInvocation invocation) throws Exception {
// String result;
// Object action = invocation.getAction();
// try {
// result = invocation.invoke();
// } catch (Exception e) {
// ActionContext actionContext = invocation.getInvocationContext();
// HttpServletResponse response = (HttpServletResponse) actionContext
// .get(StrutsStatics.HTTP_RESPONSE);
// response.setStatus(500);
// if (action instanceof EditPurInvoice) {
// ((EditPurInvoice) action).setResult(e.getMessage());
// }
// result = PARAM.AJAX_RESPONSE_CODE;
// }
String result = "";
// Object action = invocation.getAction();
ActionContext actionContext = invocation.getInvocationContext();
HttpServletResponse response = (HttpServletResponse) actionContext
.get(StrutsStatics.HTTP_RESPONSE);

try {
result = invocation.invoke();
if (result.equals(Action.ERROR)) {
response.setStatus(403);
}
} catch (Exception e) {
response.setStatus(403);
result = Action.ERROR;

}
return result;

}
}




false
actionErrors\[\d+\], fieldErrors\..+$,
actionMessages\[\d+\]
text/html


false
actionErrors\[\d+\], fieldErrors\..+$,
actionMessages\[\d+\]
text/html


false
actionErrors\[\d+\], fieldErrors\..+$,
actionMessages\[\d+\]
text/html



result="Exception" />






你可能感兴趣的:(java)