tomcat架构分析和源码解读

    最近在看《深入分析java web技术内幕》,书中讲解了一部分tomcat的相关知识,我也去查看了一些源码,看了大神们写的代码,我才知道自己就像在做加减乘除一样,这是不行的。还有好多包和类要属性。就像要盖高楼大厦一样,对其不熟悉怎么行呢?只有对底层架构了如指掌,才能流畅的写业务,同时也是一个学习的过程。

  private Context createContext(Host host, String url) {
        String contextClass = StandardContext.class.getName();
        if (host == null) {
            host = this.getHost();
        }

        if (host instanceof StandardHost) {
            contextClass = ((StandardHost)host).getContextClass();
        }

        try {
            return (Context)Class.forName(contextClass).getConstructor().newInstance();
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException | InstantiationException var5) {
            throw new IllegalArgumentException("Can't instantiate context-class " + contextClass + " for host " + host + " and url " + url, var5);
        }
    }

  Tomcat.class中的一个方法,自己实现这个方法,能够学习很多。Context和Host的关系,已经cath中多个异常的写法,还有throw和throws的写法。

-----------------------

再补充一下,在linux下安装tomcat的问题,首先就是要配置好java的path,然后有一个小问题就是,startup.sh和catlatina.sh需要更改文件的执行权限,这个比较隐蔽

 

ApplicationContext implements ServletContext

这句话可以看出Servlet的继承关系。

posted @ 2018-12-27 11:35  懂得了才能做一些改变  阅读(249)  评论(0编辑  收藏  举报