Tomcat下载安装使用教程,servlet和api(生命周期)简介

1.Tomcat的下载与安装

(1)下载Tomcat

官网地址:http://tomcat.apache.org/whichversion.html

 


(2)安装Tomcat

Tomcat有安装版和解压版(绿色版)

安装版以.exe形式的安装包,双击安装到我们的电脑上,用的比较少

解压版,即绿色版,解压后直接使用,用的比较多

 


2.Tomcat的目录结构

 


 

bin:脚本目录

         启动脚本:startup.bat

         停止脚本:shutdown.bat

conf:配置文件目录 (config /configuration)

         核心配置文件:server.xml

         用户权限配置文件:tomcat-users.xml

         所有web项目默认配置文件:web.xml

lib:依赖库,tomcat和web项目中需要使用的jar包

logs:日志文件.

         localhost_access_log.*.txt tomcat记录用户访问信息,星*表示时间。

         例如:localhost_access_log.2016-02-28.txt

temp:临时文件目录,文件夹内内容可以任意删除。

webapps:默认情况下发布WEB项目所存放的目录。

work:tomcat处理JSP的工作目录。

 

3.Tomcate的启动与运行

双击Tomcat下的bin下的startup.bat启动Tomcat

 


 

 

 

在浏览器的地址栏中输入http://localhost:8080,看到如下页面证明启动成功

 


Tomcat启动不成功的原因分析:

1)如果没有配置JAVA_HOME环境变量,在双击“startup.bat”文件运行tomcat              时,将一闪立即关闭。且必须配置正确,及JAVA_HOME指向JDK的安装目录

2)端口冲突

java.net.BindException: Address already in use: JVM_Bind <null>:8080

修改Tomcat/conf/server.xml

 

 

注意:WEB-INF目录是受保护

1.使用Eclipse绑定Tomcat并发布应用

     步骤1:获得服务器运行环境配置,Window/Preferences/Server/Runtime Environmen

 

 

 

 

 

 

 

 

 

 

 

步骤2:添加服务器

 

 

 

 

 

 

 

 

 

 

 

 

 

步骤3:选择服务器在硬盘的地址,然后所有的都是确定/Next/Finish

 

 

 

 

 

 

 

 

 

 

 

 

                

             步骤4:完成成功

 

 

 

 

 

 

         步骤5:设置发布位置

 

 

 

 

 

 

 

 

 

                修改tomcat发布的位置

 

 

 

       步骤6:项目右键/Run As/Run on Server

 

     

JavaWeb核心之Servlet

Servlet是再服务器里面的,是服务带的。项目如果不陪服务器,Servlet就用不了

 

二、Servlet简介

(接口),用来处理客户端请求、响应给浏览器的动态资源。Servlet就是类,既然是类是个接口就得实现类

实现步骤:

1)创建类实现Servlet接口

2)覆盖尚未实现的方法---重点实现service方法

3)在web.xml进行servlet的配置

但在实际开发中,我们不会直接去实现Servlet接口,因为那样需要覆盖的方法太多,    我们一般创建类继承HttpServlet

 

 

 

 

 

 

             

 

 

实现步骤:

1)创建类继承HttpServlet类

2)覆盖doGet和doPost

3)在web.xml中进行servlet的配置

三、Servlet的API(生命周期)请求和响应的生命周期

 

 

 

 

你的客户端在请求的时候又http协议包装成http请求,又TomCat解析之后立马创建了request(请求)和response(响应),在创建的时候response(响应)立没有东西的,是空的。

 

 

(1)Servlet接口中的方法

1)init(ServletConfig config)

何时执行:servlet对象创建的时候执行

ServletConfig : 代表的是该servlet对象的配置信息

 

 

 


可以通过ServletConfig config获取到这些东西,


 

 

 

 

 

 

 

2)service(ServletRequest request,ServletResponse response)

何时执行:每次请求都会执行

ServletRequest :代表请求 认为ServletRequest 内部封装的是                                                                            

            http请求的信息

ServletResponse :代表响应 认为要封装的是响应的信息

 

3)destroy()

何时执行:servlet销毁的时候执行

HttpServlet类的方法

1)init()

2)doGet(HttpServletRequest request,HttpServletResponse response)

3)doPost(HttpServletRequest request,HttpServletResponse response)

4)destroy()

 

(2)三种路径

 

1)完全匹配 访问的资源与配置的资源完全相同才能访问到

 


2)目录匹配 格式:/虚拟的目录../*   *代表任意

 


3)扩展名匹配 格式:*.扩展名

 

 



转载于:https://www.cnblogs.com/pandam/p/11255072.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
================================================================================ 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. ================================================================================ Apache Tomcat Version 8.0.15 Release Notes ========= CONTENTS: ========= * Dependency Changes * API Stability * Bundled APIs * Web application reloading and static fields in shared libraries * Security manager URLs * Symlinking static resources * Viewing the Tomcat Change Log * Cryptographic software notice * When all else fails =================== Dependency Changes: =================== Tomcat 8.0 is designed to run on Java SE 7 and later. ============== API Stability: ============== The public interfaces for the following classes are fixed and will not be changed at all during the remaining lifetime of the 8.x series: - All classes in the javax namespace The public interfaces for the following classes may be added to in order to resolve bugs and/or add new features. No existing interface method will be removed or changed although it may be deprecated. - org.apache.catalina.* (excluding sub-packages) Note: As Tomcat 8 matures, the above list will be added to. The list is not c
================================================================================ 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. ================================================================================ Apache Tomcat Version 7.0.57 Release Notes ========= CONTENTS: ========= * Dependency Changes * API Stability * JNI Based Applications * Bundled APIs * Web application reloading and static fields in shared libraries * Tomcat on Linux * Enabling SSI and CGI Support * Security manager URLs * Symlinking static resources * Viewing the Tomcat Change Log * Cryptographic software notice * When all else fails =================== Dependency Changes: =================== Tomcat 7.0 is designed to run on Java SE 6 and later. In addition, Tomcat 7.0 uses the Eclipse JDT Java compiler for compiling JSP pages. This means you no longer need to have the complete Java Development Kit (JDK) to run Tomcat, but a Java Runtime Environment (JRE) is sufficient. The Eclipse JDT Java compiler is bundled with the binary Tomcat distributions. Tomcat can also be configured to use the compiler from the JDK to compile JSPs, or any other Java compiler supported by Apache Ant. ============== API Stability: ============== The public interfaces for the following classes are fixed and will not be changed at all during the remaining lifetime of the 7.x series: - javax/**/* The public interfaces for the following classes may be added to in order to resolve bugs and/or add new features. No existing interface will be removed or changed although it may be deprecated. - org/apache/catalina/* - org/apache/catalina/comet/* Note: As Tomcat 7 matures, the above list will be added to. The list is not considered complete at this time. The remaining classes are considered part of the Tomcat internals and may change without notice between point releases. ======================= JNI Based Applications: ======================= Applications that require native libraries must ensure that the libraries have been loaded prior to use. Typically, this is done with a call like: static { System.loadLibrary("path-to-library-file"); } in some class. However, the application must also ensure that the library is not loaded more than once. If the above code were placed in a class inside the web application (i.e. under /WEB-INF/classes or /WEB-INF/lib), and the application were reloaded, the loadLibrary() call would be attempted a second time. To avoid this problem, place classes that load native libraries outside of the web application, and ensure that the loadLibrary() call is executed only once during the lifetime of a particular JVM. ============= Bundled APIs: ============= A standard installation of Tomcat 7.0 makes all of the following APIs available for use by web applications (by placing them in "lib"): * annotations-api.jar (Annotations package) * catalina.jar (Tomcat Catalina implementation) * catalina-ant.jar (Tomcat Catalina Ant tasks) * catalina-ha.jar (High availability package) * catalina-tribes.jar (Group communication) * ecj-4.4.jar (Eclipse JDT Java compiler) * el-api.jar (EL 2.2 API) * jasper.jar (Jasper 2 Compiler and Runtime) * jasper-el.jar (Jasper 2 EL implementation) * jsp-api.jar (JSP 2.2 API) * servlet-api.jar (Servlet 3.0 API) * tomcat7-websocket.jar (WebSocket 1.1 implementation) * tomcat-api.jar (Interfaces shared by Catalina and Jasper) * tomcat-coyote.jar (Tomcat connectors and utility classes) * tomcat-dbcp.jar (package renamed database connection pool based on Commons DBCP) * tomcat-jdbc.jar (Tomcat's database connection pooling solution) * tomcat-util.jar (Various utilities) * websocket-api.jar (WebSocket 1.1 API) You can make additional APIs available to all of your web applications by putting unpacked classes into a "classes" directory (not created by default), or by placing them in JAR files in the "lib" directory. To override the XML parser implementation or interfaces, use the endorsed mechanism of the JVM. The default configuration defines JARs located in "endorsed" as endorsed. ================================================================ Web application reloading and static fields in shared libraries: ================================================================ Some shared libraries (many are part of the JDK) keep references to objects instantiated by the web application. To avoid class loading related problems (ClassCastExceptions, messages indicating that the classloader is stopped, etc.), the shared libraries state should be reinitialized. Something which might help is to avoid putting classes which would be referenced by a shared static field in the web application classloader, and putting them in the shared classloader instead (JARs should be put in the "lib" folder, and classes should be put in the "classes" folder). ================ Tomcat on Linux: ================ GLIBC 2.2 / Linux 2.4 users should define an environment variable: export LD_ASSUME_KERNEL=2.2.5 Redhat Linux 9.0 users should use the following setting to avoid stability problems: export LD_ASSUME_KERNEL=2.4.1 There are some Linux bugs reported against the NIO sendfile behavior, make sure you have a JDK that is up to date, or disable sendfile behavior in the Connector.<br/> 6427312: (fc) FileChannel.transferTo() throws IOException "system call interrupted"<br/> 5103988: (fc) FileChannel.transferTo should return -1 for EAGAIN instead throws IOException<br/> 6253145: (fc) FileChannel.transferTo on Linux fails when going beyond 2GB boundary<br/> 6470086: (fc) FileChannel.transferTo(2147483647, 1, channel) cause "Value too large" exception<br/> ============================= Enabling SSI and CGI Support: ============================= Because of the security risks associated with CGI and SSI available to web applications, these features are disabled by default. To enable and configure CGI support, please see the cgi-howto.html page. To enable and configue SSI support, please see the ssi-howto.html page. ====================== Security manager URLs: ====================== In order to grant security permissions to JARs located inside the web application repository, use URLs of of the following format in your policy file: file:${catalina.base}/webapps/examples/WEB-INF/lib/driver.jar ============================ Symlinking static resources: ============================ By default, Unix symlinks will not work when used in a web application to link resources located outside the web application root directory. This behavior is optional, and the "allowLinking" flag may be used to disable the check. ============================== Viewing the Tomcat Change Log: ============================== See changelog.html in this directory. ============================= Cryptographic software notice ============================= This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See <http://www.wassenaar.org/> for more information. The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms. The form and manner of this Apache Software Foundation distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code. The following provides more details on the included cryptographic software: - Tomcat includes code designed to work with JSSE - Tomcat includes code designed to work with OpenSSL ==================== When all else fails: ==================== See the FAQ http://tomcat.apache.org/faq/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值