0

このクラスは、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("コントローラー - 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()
  {
  }

}
4

0 に答える 0