Azkaban的Web Server源碼探究系列13:首頁/index的內容獲取

上節,講到了跳轉到/indexweb

ServletHolder index = new ServletHolder(new ProjectServlet());session

root.addServlet(index, "/index");app

因此須要調研ProjectServlet的方法webapp

=====================================================================ide

1)initspa

ci

2)doGetget


@Overrideservlet

  protected void handleGet(HttpServletRequest req, HttpServletResponse resp,it

      Session session) throws ServletException, IOException {

  //這裏,不執行

    if (hasParam(req, "doaction")) {

      if (getParam(req, "doaction").equals("search")) {

        String searchTerm = getParam(req, "searchterm");

        if (!searchTerm.equals("") && !searchTerm.equals(".*")) {

          handleFilter(req, resp, session, searchTerm);

          return;

        }

      }

    }

    //獲取user

    User user = session.getUser();

    //這裏

    ProjectManager manager =

        ((AzkabanWebServer) getApplication()).getProjectManager();

    //構造page

    Page page =

        newPage(req, resp, session, "azkaban/webapp/servlet/velocity/index.vm");

 

    if (lockdownCreateProjects && !hasPermissionToCreateProject(user)) {

      page.add("hideCreateProject", true);

    }

 

    if (hasParam(req, "all")) {

      List<Project> projects = manager.getProjects();

      page.add("viewProjects", "all");

      page.add("projects", projects);

    } else if (hasParam(req, "group")) {

      List<Project> projects = manager.getGroupProjects(user);

      page.add("viewProjects", "group");

      page.add("projects", projects);

    } else {

     //默認的配置就會走這條路

      List<Project> projects = manager.getUserProjects(user);

      page.add("viewProjects", "personal");

      page.add("projects", projects);

    }

    //渲染

    page.render();

  }

最終結果:

相關文章
相關標籤/搜索