一,server.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8006" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <Listener className="org.apache.catalina.core.JasperListener"/>
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
  <GlobalNamingResources>
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
    <Engine defaultHost="localhost" name="Catalina">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>
      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>
      <Context docBase="D:\workspace\app-lisi\wangwu\src\main\webapp" path="/wangwu" reloadable="true"/></Host>
    </Engine>
  </Service>
</Server>

localhost:8080就是服务器的配置好的。具体怎么改加tomacat(一)的说明。

其中我们可以看到D:\workspace\app-lisi\wangwu\src\main\webapp这个路径,现在假如浏览器来访问的时候会设置一个虚拟路径而这个虚拟路径就是path="/wangwu",到时候假如我们访问的是

localhost:8080/wangwu/1.jsp就相当于访问的是 localhost:8080/D:\workspace\app-lisi\wangwu\src\main\webapp\1.jsp

二,web.xml的注意点

context.xml文件

 <Context>

     <WatchedResource>WEB-INF/web.xml</WatchedResource>
 </Context>

从context.xml中我们可以看到,tomcat会默认首先去加载项目下的web.xml的文件

假如在我们现在是新建的项目,就可以把tomacat下的web.xml文件直接复制到自己的项目的WEB-INF的目录下就行了。

在这里需要注意的就是tomcat的web.xml问价的抬头和项目的web.xml的抬头不一定非得一样。

这是我用的tomcat的web.xml的内容

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                       http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   version="3.0"
   metadata-complete="true">

   <display-name>Welcome to Tomcat</display-name>
   <description>
      Welcome to Tomcat
   </description>
 </web-app>

这是我项目中的web.xml的内容

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
     version="2.4">
     <context-param>
         <param-name>webAppRootKey</param-name>
         <param-value>bossintra.root</param-value>
     </context-param>

     <context-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>
             classpath:context/init/applicationService.xml
         </param-value>
     </context-param>

     <!-- 读取spring配置的listener -->
     <listener>
         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>

     <filter>
         <filter-name>sitemesh</filter-name>
         <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
     </filter>
     <filter-mapping>
         <filter-name>sitemesh</filter-name>
         <url-pattern>*.htm</url-pattern>
     </filter-mapping>
     <filter-mapping>
         <filter-name>sitemesh</filter-name>
         <url-pattern>*.ftl</url-pattern>
     </filter-mapping>
     <!-- 处理中文字符编码的过滤器配置 -->
     <filter>
         <filter-name>Set Character Encoding</filter-name>
         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
         <init-param>
             <param-name>encoding</param-name>
             <param-value>UTF-8</param-value>
         </init-param>
         <init-param>
             <param-name>forceEncoding</param-name>
             <param-value>true</param-value>
         </init-param>
     </filter>
     <filter-mapping>
         <filter-name>Set Character Encoding</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>

     <!-- 装饰时的过滤sitemesh针对freemarker的支持 -->
     <servlet>
         <servlet-name>sitemesh-freemarker</servlet-name>
         <servlet-class>
             com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet
         </servlet-class>
         <init-param>
             <param-name>TemplatePath</param-name>
             <param-value>/</param-value>
         </init-param>
         <init-param>
             <param-name>default_encoding</param-name>
             <param-value>UTF-8</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>

     <servlet-mapping>
         <servlet-name>sitemesh-freemarker</servlet-name>
         <url-pattern>*.ftl</url-pattern>
     </servlet-mapping>

     <servlet>
         <servlet-name>seashell</servlet-name>
         <servlet-class>
             org.springframework.web.servlet.DispatcherServlet
         </servlet-class>
         <init-param>
             <param-name>contextConfigLocation</param-name>
             <param-value>
                 classpath:context/init/applicationContext.xml
             </param-value>
         </init-param>
         <load-on-startup>3</load-on-startup>
     </servlet>

     <!--spring controller对应的扩展名-->
     <servlet-mapping>
         <servlet-name>seashell</servlet-name>
         <url-pattern>*.htm</url-pattern>
     </servlet-mapping>
     <servlet-mapping>
         <servlet-name>seashell</servlet-name>
         <url-pattern>*.do</url-pattern>
     </servlet-mapping>

     <jsp-config>

          <taglib>
             <taglib-uri>sitemesh-decorator</taglib-uri>
             <taglib-location>
                 /WEB-INF/tld/sitemesh-decorator.tld
             </taglib-location>
         </taglib>

         <taglib>
             <taglib-uri>sitemesh-page</taglib-uri>
             <taglib-location>
                 /WEB-INF/tld/sitemesh-page.tld
             </taglib-location>
         </taglib>

         <taglib>
             <taglib-uri>/WEB-INF/spring.tld</taglib-uri>
             <taglib-location>/WEB-INF/tld/spring.tld</taglib-location>
         </taglib>

         <taglib>
             <taglib-uri>/WEB-INF/spring-form.tld</taglib-uri>
             <taglib-location>
                 /WEB-INF/tld/spring-form.tld
             </taglib-location>
         </taglib>
     <taglib>
             <taglib-uri>/WEB-INF/tld/page.tld</taglib-uri>
             <taglib-location>
                 /WEB-INF/tld/page.tld
             </taglib-location>
         </taglib>
     </jsp-config>
 <distributable />
 </web-app>

tomcat原理(三)结合公司tomcat的用法的在理解的更多相关文章

  1. Tomcat 原理篇

    TOMCAT 原理篇一.Tomcat 组成(Tomcat 由以下组件组成) 1.server a) Server是一个Catalina Servlet容器: b) Server 可以包含一个或多个se ...

  2. Tomcat 的三种(bio,nio.apr) 高级 Connector 运行模式及apr配置

    转: http://www.oschina.net/question/54100_16195omcat的运行模式有3种.修改他们的运行模式.3种模式的运行是否成功,可以看他的启动控制台,或者启动日志. ...

  3. Linux配置tomcat (centos配置java环境 tomcat配置篇 总结三)

    ♣下载安装tomcat7 ♣设置启动和关闭 ♣设置用户名和密码 ♣发布java web项目 声明:这篇教程是建立在前两篇教程的基础上的,所以,还没安装工具和jdk,可以先看这个系列的前面两篇(去到文末 ...

  4. tomcat原理解析(一):一个简单的实现

    tomcat原理解析(一):一个简单的实现 https://blog.csdn.net/qiangcai/article/details/60583330 2017年03月07日 09:54:27 逆 ...

  5. tomcat原理分析与简单实现

    tomcat原理分析与简单实现 https://blog.csdn.net/u014795347/article/details/52328221 2016年08月26日 14:48:18 卫卫羊习习 ...

  6. tomcat(三)--基本安装配置

    0x01  JDK和Tomcat安装 到oracle官网下载jdk,当前下载的版本是Linux x64 jdk-8u101-linux-x64.tar.gz 到apache官网下载tomcat,当前最 ...

  7. Java Web开发Tomcat中三种部署项目的方法

    第一种方法:在tomcat中的conf目录中,在server.xml中的,<host/>节点中添加: <Context path="/hello" docBase ...

  8. JSP学习笔记(三):简单的Tomcat Web服务器

    注意:每次对Tomcat配置文件进行修改后,必须重启Tomcat 在E盘的DATA文件夹中创建TomcatDemo文件夹,并将Tomcat安装路径下的webapps/ROOT中的WEB-INF文件夹复 ...

  9. TOMCAT原理详解及请求过程(转载)

    转自https://www.cnblogs.com/hggen/p/6264475.html TOMCAT原理详解及请求过程 Tomcat: Tomcat是一个JSP/Servlet容器.其作为Ser ...

随机推荐

  1. BZOJ 3944: Sum [杜教筛]

    3944: Sum 贴模板 总结见学习笔记(现在还没写23333) #include <iostream> #include <cstdio> #include <cst ...

  2. BZOJ 1415: [Noi2005]聪聪和可可 [DP 概率]

    传送门 题意:小兔子乖乖~~~ 题意·真:无向图吗,聪抓可,每个时间聪先走可后走,聪一次可以走两步,朝着里可最近且点编号最小的方向:可一次只一步,等概率走向相邻的点或不走 求聪抓住可的期望时间 和游走 ...

  3. http协议重点

    https://www.cnblogs.com/ranyonsue/p/5984001.html HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议) ...

  4. webstorm你不知道的秘密

    相信你们用webstorm肯定都会用上下面介绍的Emmet插件这个可以自带的哦 Emmet语法 子代:> 兄弟:+ 父代:^ 重复:* 成组:() ID:# class:. 属性:[] 编号:$ ...

  5. DaemonSet 典型应用场景 - 每天5分钟玩转 Docker 容器技术(129)

    Deployment 部署的副本 Pod 会分布在各个 Node 上,每个 Node 都可能运行好几个副本.DaemonSet 的不同之处在于:每个 Node 上最多只能运行一个副本. DaemonS ...

  6. 网络配置:linux学习第一篇

    1.      先使用dhclient获取ip 再使用命令ip addr查看获取到的ip 2.      设置静态IP 编辑网卡配置文件,路径: 3.      重启网络服务 命令:systemctl ...

  7. Zabbix监控之迁移zabbix server

    abbix监控中有时会根据需要对zabbix服务器进行迁移,zabbix迁移是非常简单的,因为zabbix的前端所有的操作都存在zabbix数据库里.所以zabbix迁移只需对zabbix库中相应的表 ...

  8. VC下防止反汇编的办法(1)

    最近在看IDA的书,讲汇编语言的部分提到了一种防止递归向下汇编器逆向程序的方法 这里esp指向栈顶,也就是调用方最后入栈的返回地址.然而实际在VC2017里用内联汇编这么做是不行的,原因可以看看VC生 ...

  9. Three.js 学习笔记(1)--坐标体系和旋转

    前言 JavaScript 3D library The aim of the project is to create an easy to use, lightweight, 3D library ...

  10. 【Unity3D技术文档翻译】第1.0篇 AssetBundles

    前言 "Unity圣典"是目前对官方文档翻译比较详细的,然而文档的最新更新日期是2013年,已经远远落后最新版本,参考意义有限.官方文档.脚本手册是学习Unity3D最直接有效的途 ...