对Servlet容器的补充
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                对Servlet容器的补充
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                【0】README
0.1)本文是對 一個簡單的servlet容器?的補充;
 
【1】Servlet容器
1.1)通過一個簡單的servlet容器這篇博文,我們看到:其中的核心代碼是 類加載器, 然而,在我follow 其代碼,分別在命令行 和 Eclipse 執行時,得到了不同的執行結果; 參見我的提問?對于URLClassLoader,Eclipse執行正確,而命令行執行拋出異常?這個問題描述;
1.2)拋出異常的原因: 顯然是 類加載器沒有找到要加載類所在的dir, 然而,正如你所見,我在 URLClassLoader的源代碼中已經 指定了加載路徑;
try {// create a URLClassLoader, 創建類載入器(類加載器是干貨代碼 )URL[] urls = new URL[1];URLStreamHandler streamHandler = null;File classPath = new File(Constants.WEB_ROOT);// the forming of repository is taken from the createClassLoader method in// org.apache.catalina.startup.ClassLoaderFactoryString repository = (new URL("file", null, classPath.getCanonicalPath() + File.separator)).toString() ;// file:E:\bench-cluster\cloud-data-preprocess\HowTomcatWorks\webroot\// the code for forming the URL is taken from the addRepository method in// org.apache.catalina.loader.StandardClassLoader class.urls[0] = new URL(null, repository, streamHandler);// urls[0] = file:E:/bench-cluster/cloud-data-preprocess/HowTomcatWorks/webroot/loader = new URLClassLoader(urls);}
1.3)解決方法:正如你在 “一個簡單的servlet容器” 這篇博文中所見,我需要再 命令行運行該程序時,手動添加 類加載路徑到 classpath, 這樣才能執行成功,否則失敗。
 
 
Attention)我納悶的地方在于:明明在上述代碼中,我已經在 URLClassLoader的類構造器中指明了 類加載路徑,為什么我還要在命令行手動設置類加載路徑到 classpath,那豈不是我在URLClassLoader 中指明的 類加載路徑是 invalid ? 也就是上述我在技術問題中所提出的問題,但是這個問題一直沒有人來解答。
 
 
總結
以上是生活随笔為你收集整理的对Servlet容器的补充的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: tomcat(2)一个简单的servle
- 下一篇: 3d字怎么制作(3d字如何制作)
