6TomCat

--- --- restore content begins

One. WEB base     

      1. WEB development of knowledge

              ○ WEB, that means in English web pages mean, it used to represent the Internet for reference by the host resources outside access.

              ○ Internet altar Web access outside resources are divided into:

                     § static web resources (such as html page): refers to a web page for people to browse the data is always the same.

                     § dynamic web resources: refers to the data for people to browse the web page is generated by the program, visit different points in time to see the content of the web pages vary.

              ○ static web resources exploitation

                     § Html、CSS、javaScript

              ○ commonly used dynamic web development technology resources:

                     § JSP/Servlet、ASP、PHP等

                     § In Java, dynamic web development technology resources collectively referred to as Javaweb, the focus of our program is to teach you how to use Java technology to develop dynamic web resources that dynamic web pages.

       2. WEB server

              Learning web development, you need to install a web server, and then develop the appropriate web resources on a web server for users to use the browser to access.

              Note: The server is not mentioned here refers to the server hardware resources, but to the server software.

       3. Common WEB server

              BEA WebLogic is the company's products, is currently the most widely used Web server that supports the J2EE specification, and continuous improvement to meet the new requirements of development, start interface shown in Figure

                                         

              Another commonly used Web server is IBM's WebSphere, support the J2EE specification, start the interface shown in Figure

                                                                     

 

 

              在小型的应用系统或者有特殊需要的系统中,可以使用一个 免费的Web服务器:Tomcat,该服务器支持全部JSP以及Servlet规范,启动界面如图

                                                                     

。TomCat

 

     1. TOMCAT服务器的安装与配置

 

              常见服务器:WebLogic(BEA)、webSphere(IBM)、Tomcat(Apache)

 

              a. Tomcat 的下载与安装

 

                     § 下载地址:http://tomcat.apache.org/

       § 获取Tomcat安装程序包 能用压缩版就用压缩版

                            □ tar.gz文件是Linux操作系统下的安装版本

                            □ exe文件是Windows系统下的安装版本

                            □ zip文件是Windows系统下的压缩版本

 

 

 

 

Tomcat 9 可能会出现乱码 就是启动项加载的时候,可以自己上网

•      安装Tomcat

   注意事项(常见问题):

•      安装目录不能包含中文和空格。

•      JAVA_HOME环境变量指定Tomcat运行时所要用的jdk所在的位置,注意,配到目录就行了,不用指定到bin。一定要是JAVA_HOME 因为tomcat 在启动时会自动查找这个变量,因为

tomcat是java编写的

•      端口占用问题:netstat -ano命令查看端口占用信息。

•      Catalina_Home环境变量:startup.bat启动哪个tomcat由此环境变量指定,如果不配置则启动当前tomcat,推荐不要配置此环境变量。

   安装完成后:

双击 tomcat/bin 目录下的 startup.bat 文件

在浏览器端输入   http://localhost:8080/       显示如下界面代表安装成功

2.启动tomcat

                     i. 启动一闪而过:

                            1) 原因一:JAVA_HOME环境变量名称不合法。

                            2) 原因二:JAVA_HOME包保存的jdk路径无效。tomcat依赖于jdk。

                            3) 原因三:端口被占用。net stop  https

                                   查看端口号对应的pid

                                          netstat -ano

                                   打开任务管理器,关闭80或8080对应的pid进程。

                            4) 原因四:tomcat安装路径中不允许出现中文和空格。否则会导致不必要的错误。

看端口是否被占用

 

 

4代表端口被https协议占用  解决代码:

 

还有一种比较暴力的window任务管理器 -->详细信息

 

3.Tomcat的目录结构

  • bin--存放tomcat启动关闭所用的批处理文件   shutdown.bat 关闭服务器   startup.bat 开启服务器
  • conf--tomcat的配置文件,最终要的是server.xml
    • *实验:修改servlet.xml,更改tomcat运行所在的端口号,从8080改为80
    • lib--tomcat运行所需jar包
    • logs--tomcat运行时产生的日志文件
    • temp--tomcat运行时使用的临时目录,不需要我们关注
    • webapps--虚拟主机和web应用所应存放的目录 存储的是tomcat运行时所需要的web资源的目录
    • work--tomcat工作目录,后面学jsp用到
    • 三 虚拟主机

1. 虚拟主机概念

              在一个真实的服务器中,运行着多个网站,这些网站在用户看来是运行在各自独立的服务器当中,但是真实的情况却是运行在同一个服务器中。这些网站可以称之为主机,由于网站没有运行在各自的服务器中,所以可以把这些主机称之为虚拟主机。一个网站就是一台虚拟主机。

       2. web应用概念

              由于虚拟主机无法直接管理web资源,所以将web资源放入虚拟主机管理目录中的一个子目录内。这个目录管理同一功能的web资源,多个功能不同的web资源放入不同的目录中。一般情况下,web应用会根据功能划分,一个功能一个web应用。

       3. web应用

              a. web应用是一个目录,其中存放一个功能的全部web资源。(动态和静态的).在一个虚拟主机中,可以包含多个这样的目录。web应用全称叫做web应用目录。

              b. web资源:

                     静态资源:HTML、IMG、CSS、JS、jQuery

                     动态资源:Servlet/jsp

              c. web是网页的意思。需要将web内容放在Internet网络中,才能被其他互联网中的用户访问。所以web应用也需要这样做。

              d. web应用被访问的方法:

                     提供web应用的虚拟路径。

              e. 虚拟路径必须要映射在真实的web应用目录身上,这样在地址栏中访问虚拟路径的时候,才会得到对应的web资源。

       4. web应用虚拟路径的创建方式:

              第一种:在server.xml中找到<Host>标签,在其中添加一个<Context path=""  docBase=""/>其中path存储虚拟路径,docBase存储真实路径。

              第二种:在conf/Catalina/localhost目录中添加一个以虚拟路径命名的.xml文件。文件中存储web应用的真实路径。书写内容如下:

                     <Context  docBase="真实路径"  />

                     注意:由于虚拟路径是xml文件的名称,window中不允许使用"/"命名文件,所以如果虚拟路径中存在多级路径,可以通过"#"来分割。

              第三种:在webapps目录中添加一个子目录,这个目录的名称就是虚拟路径的名称。

       5. 缺省web应用

              一个web应用可以配置为缺省web应用, 这样在访问缺省web应用的时候,就不用书写web应用的虚拟路径名称。

              第一种:在server.xml中找到<Host>标签,在其中添加一个<Context path=""  docBase=""/>path中不需要书写任何内容,这时当前web应用就会作为缺省使用。

              第二种:在conf/Catalina/localhost目录中添加一个以虚拟路径命名的.xml文件。作为缺省web应用,需要将文件名配置为ROOT.xml

              第三种:在webapps目录中添加一个子目录,这个目录的名称就是虚拟路径的名称。 并且名称必须叫做ROOT.

              缺省优先级:

                     server.xml  >  conf/Catalina/localhost >  webapps

       6. web应用目录结构

             

              web应用

              |

              |---存放静态web资源,此处存放的静态web资源可以被直接访问

              |

              |---WEB-INF

                     |---  静态web资源   此处存放的静态web资源不可以被直接访问。

                     |---lib            当前web应用所依赖的jar包

                     |---classes    存放动态资源的目录

                     |---web.xml  用于配置当前web应用,可以配置缺省主页,servlet映射,监听器和过滤器。

              一个web应用的目录结构可以不完整,但是如果要构建完整web应用,则需要严格遵循上述结构。

              a. 练习创建完整的web应用目录结构

              b. 添加缺省主页:

                     在web.xml中添加如下配置:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1">
      <welcome-file-list>
        <welcome-file>1.html</welcome-file>
    
    </welcome-file-list>

</web-app>

 

Guess you like

Origin www.cnblogs.com/xuwangqi/p/11314577.html