您的位置:首页 > 其它

structs2与ajax结合的经验

2015-11-03 09:45 253 查看
  structs2与ajax结合,无论采用$.post还是$.ajax都捕获不到服务器产生的错误,这是structs2内部设计的不是很好,

  但是$.ajax捕获错误在servlet能做到。因为

  public void serviceAction(HttpServletRequest request, HttpServletResponse response, ServletContext context,

  ActionMapping mapping) throws ServletException {

  Map extraContext = createContextMap(request, response, mapping, context);

  // If there was a previous value stack, then create a new copy and pass it in to be used by the new Action

  ValueStack stack = (ValueStack) request.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY);

  boolean nullStack = stack == null;

  if (nullStack) {

  ActionContext ctx = ActionContext.getContext();

  if (ctx != null) {

  stack = ctx.getValueStack();

  }

  }

  if (stack != null) {

  extraContext.put(ActionContext.VALUE_STACK, valueStackFactory.createValueStack(stack));

  }

  String timerKey = "Handling request from Dispatcher";

  try {

  UtilTimerStack.push(timerKey);

  String namespace = mapping.getNamespace();

  String name = mapping.getName();

  String method = mapping.getMethod();

  Configuration config = configurationManager.getConfiguration();

  ActionProxy proxy = config.getContainer()。getInstance(ActionProxyFactory.class)。createActionProxy(

  namespace, name, method, extraContext, true, false);

  request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation()。getStack());

  // if the ActionMapping says to go straight to a result, do it!

  if (mapping.getResult() != null) {

  Result result = mapping.getResult();

  result.execute(proxy.getInvocation());

  } else {

  proxy.execute();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: