无法转发...响应已经提交

时间:2013-06-21 14:12:24

标签: javascript servlets websphere

此类将用于实例化BaseAction Factory并将操作传递给控制器​​

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class Controller extends HttpServlet {
    private static final long serialVersionUID = 1L;

  private static final Logger log = Logger.getLogger(Controller.class);

  public void init() {

 }

  public void doGet(HttpServletRequest _req, HttpServletResponse _res)
    throws ServletException, IOException
  {

/ *转发到doPost方法* /

    doPost(_req, _res);
  }

  public void doPost(HttpServletRequest _req, HttpServletResponse _res)
    throws ServletException, IOException
  {

    String view = null;
    boolean redirect = false ;

    try {

/ *使用帮助器* /

包装请求对象
      ReqUtility reqUtil = new ReqUtility(_req);

/ *根据请求参数创建一个BaseAction对象* /           BaseAction action = reqUtil.getAction();           log.debug(" Controller - getAction" + _req.getQueryString()+"" + _req.getPathInfo());

/ *执行业务逻辑* /

      boolean retval = action.execute(_req, _res) ;

/ 如果这是消费者操作,我们已经重定向到eDirect,所以只需返回 /

      String className = action.getClass().getName();
      boolean consumerWizardAction = (className.contains("ApplWizardAction"));
      log.debug("Controller. className = ["+className+"], consumerWizardAction ["+consumerWizardAction+"]");
      if (!retval && consumerWizardAction) {
          log.debug("returning after redirect");
          redirect = true;
          return ;
      }

/ *获取适当的行动视图* /

      view = action.getView();

      if(null == view) throw new ServletException("No view specified in action: "+action.getClass().getName());


    if (!redirect) {
          /* Forward the request to the given view */
          RequestDispatcher dispatcher = _req.getRequestDispatcher(view);
          if( _req.getParameter("includeView") != null) {
            _res.setContentType("text/html");
            dispatcher.include(_req, _res);
          } else {
            dispatcher.forward(_req, _res);
          }

    }



    }catch (Exception e) {
      /* Forward the error to the error.jsp page */
      log.debug("Controller - exception " + e.toString());

      _req.setAttribute("javax.servlet.jsp.jspException", e);
      view = "/error.jsp";
      e.printStackTrace();
    }

  }

  public void destroy()
  {
  }

}

0 个答案:

没有答案