若是請求的URI是"/",對應的servlet如何響應?web
===================================================================ajax
ServletHolder indexRedirect = new ServletHolder(new IndexRedirectServlet(defaultServletPath));spring
root.addServlet(indexRedirect, "/");session
===================================================================app
因此須要分析IndexRedirectServletwebapp
1)servlet的init方法ide
這裏涉及到了3個類,分別是:學習
IndexRedirectServlet LoginAbstractAzkabanServlet AbstractAzkabanServletthis
首先找這3個類的init方法---第一個init方法在LoginAbstractAzkabanServlet spa
因此須要從這個類的init方法開始看
AbstractAzkabanServlet.init
@Override
public void init(ServletConfig config) throws ServletException {
//看到這裏了
application =//獲取以前的server實例
(AzkabanServer) config.getServletContext().getAttribute(
AzkabanServletContextListener.AZKABAN_SERVLET_CONTEXT_KEY);
if (application == null) {
throw new IllegalStateException(
"No batch application is defined in the servlet context!");
}
//看到這裏了
Props props = application.getServerProps();
//看到這裏了
name = props.getString("azkaban.name", "");//獲取名字
label = props.getString("azkaban.label", "");//label
color = props.getString("azkaban.color", "#FF0000");//顏色
if (application instanceof AzkabanWebServer) {//
AzkabanWebServer server = (AzkabanWebServer) application;//轉化
//
viewerPlugins = PluginRegistry.getRegistry().getViewerPlugins();//內容爲空
//
triggerPlugins =
new ArrayList<TriggerPlugin>(server.getTriggerPlugins().values());
}
}
---而後是
LoginAbstractAzkabanServlet.init
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
//繼續
multipartParser = new MultipartParser(DEFAULT_UPLOAD_DISK_SPOOL_SIZE);
//上面是經過commons-upload來獲取
shouldLogRawUserAgent =
getApplication().getServerProps().getBoolean("accesslog.raw.useragent",
false);
}
-------------------
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Set session id
// 入口在這
//獲取session
Session session = getSessionFromRequest(req);
//記錄本次訪問行爲
logRequest(req, session);
//第1次不執行
if (hasParam(req, "logout")) {
resp.sendRedirect(req.getContextPath());
if (session != null) {
getApplication().getSessionCache().removeSession(session.getSessionId());
}
return;
}
//不執行
if (session != null) {
if (logger.isDebugEnabled()) {
logger.debug("Found session " + session.getUser());
}
if (handleFileGet(req, resp)) {
return;
}
handleGet(req, resp, session);
} else {
if (hasParam(req, "ajax")) {
HashMap<String, String> retVal = new HashMap<String, String>();
retVal.put("error", "session");
this.writeJSON(resp, retVal);
} else {
//真正處理邏輯
handleLogin(req, resp);
}
}
}
因此,須要繼續查看handleLogin的代碼
private void handleLogin(HttpServletRequest req, HttpServletResponse resp, String errorMsg)
throws ServletException, IOException {
//1)生成數據
Page page = newPage(req, resp, "azkaban/webapp/servlet/velocity/login.vm");
if (errorMsg != null) {
page.add("errorMsg", errorMsg);
}
//渲染
page.render();
}
這部分跟springMVC就相似了,就不細說了!
主要看下azkaban/webapp/servlet/velocity/login.vm的內容
好,因此,,咱們就能看到了
怎麼樣,是否是很酷
---
經過學習azkaban,能夠了解如下知識
Jetty DBUtils Velocity(渲染)。