1.直接通過github搜索tomcat,正好找到一位有部分翻譯內容的版本,直接fork並下載git clone https://github.com/codefollower/Tomcat-Research.git2.轉換成eclipse項目工程,如果沒有安裝maven,可以先配置maven環境變...
1.直接通過github搜索tomcat,正好找到一位有部分翻譯內容的版本,直接fork並下載
git clone https://github.com/codefollower/Tomcat-Research.git
2.轉換成eclipse項目工程,如果沒有安裝maven,可以先配置maven環境變數
sudo mvn eclipse:eclipse
3.在eclipse中導入
File->Import->General->Existing Projects into Workspace
4.導入後的效果如圖所示
5.Eclipse中右擊start-tomcat.launch這個文件,點Run As啟動Tomcat,點Debug As可以調試Tomcat
6.效果如圖所示
7.啟動後通過地址http://127.0.0.1:8080/訪問
8.這時候通過上文的類似Manager App打開無法訪問(http://www.cnblogs.com/lixiaojiao-hit/p/5095180.html)
9.直接webapp目錄下的manager host-manager docs目錄放到launch/webapps目錄下
10.並按照上文中的配置進行修改,在tomcat-users.xml中進行相關配置
<role rolename="tomcat" />
<role rolename="role1" />
<user username="tomcat" password="tomcat"
roles="tomcat,admin,manager,manager-gui,manager-script,manager-jax,manager-status,admin-gui" />
<user username="both" password="tomcat" roles="tomcat,role1" />
<user username="role1" password="tomcat" roles="role1" />
11.這時候訪問查看manager app頁面就可以訪問了
12.隨便點擊按鈕,調試一下源碼,比如stop應用,審查一下源代碼
13.發現訪問路徑為/manager/html/stop?path=/docs&org.apache.catalina.filters.CSRF_NONCE=95AC2B2A81FB328CA52AF996C7F02EB4
14.查看下後臺日誌,切換到apache-tomcat-8.0.30/logs目錄下看下日誌,tail -f 10000 localhost_access_log.2016-01-03.txt
15.那麼找到web.xml中找到相關配置文件
<servlet> <servlet-name>Manager</servlet-name> <servlet-class>org.apache.catalina.manager.ManagerServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> </servlet>
16.發現相關servlet為ManagerServlet,打開ManagerServlet.java文件後發現相關代碼
17.找到stop代碼,直接停止到相對應的context也就是web應用
1 protected void stop(PrintWriter writer, ContextName cn, 2 StringManager smClient) { 3 4 if (debug >= 1) 5 log("stop: Stopping web application '" + cn + "'"); 6 7 if (!validateContextName(cn, writer, smClient)) { 8 return; 9 } 10 11 String displayPath = cn.getDisplayName(); 12 13 try { 14 Context context = (Context) host.findChild(cn.getName()); 15 if (context == null) { 16 writer.println(smClient.getString("managerServlet.noContext", 17 RequestUtil.filter(displayPath))); 18 return; 19 } 20 // It isn't possible for the manager to stop itself 21 if (context.getName().equals(this.context.getName())) { 22 writer.println(smClient.getString("managerServlet.noSelf")); 23 return; 24 } 25 context.stop(); 26 writer.println(smClient.getString( 27 "managerServlet.stopped", displayPath)); 28 } catch (Throwable t) { 29 ExceptionUtils.handleThrowable(t); 30 log("ManagerServlet.stop[" + displayPath + "]", t); 31 writer.println(smClient.getString("managerServlet.exception", 32 t.toString())); 33 } 34 35 }