servlet——1介绍

Tomcat

1、介绍

Tomcat:是一个容器,容器里面放的是Servlet;Servlet:是写的一个程序(main方法)

官网:http://www.apache.org/;它是一个开源社区;又翻译为孵化器;所有的框架软件都可以往这里提,经过一部分孵化以后,升级为一个二级域名;将来学习java框架的90%都出自apache;

apache的logo是羽毛:

官网:http://tomcat.apache.org/,它是tomcat官网,是一个二级域名;

tomcat不成文的规定:

Tomcat7对应的是jdk7

Tomcat8对应的是jdk8

Tomcat9对应的是jdk9

下载地址:https://tomcat.apache.org/download-80.cgi

下载linux的tar包,因为在windows和linux都好使用;

 

2、安装步骤

  1. 将”apache-tomcat-8.0.48.tar.gz”解压到任何一个目录,就可以使用了;
  2. 一般建议:将apache-tomcat-8.0.48改为apache-tomcat
  3. 目录介绍:

  1. Bin:可执行文件,双击就可以运行
  2. Conf:configuration,里面放的是一些配置项,java里面的属性文件(properties)
  3. Lib:下面放的是jar包;里面放的是class;
  4. Logs:日志;(流水账的日记)
    Temp:临时文件
  5. Webapps:web applications:(web的应用程序);web:网站,网页,bs(Broswer Server)都叫web
  6. Work:工作;这下面放的是jsp编后的文件(后面说)

 

启动tomcat,双击就可以;启动后不要关掉;7*24不要关机;

bin/startup.bat

启动成功:

 

客户端访问:启动一个浏览器;输入以下url:

http://localhost:8080/

http://127.0.0.1:8080/

http://192.168.1.2:8080/

(本机ip,可以局域内部,都可以访问)

 

 

停止服务:

bin/shutdown.bat

 

另外一种启动方法:

 

另外一种关闭的方法:

    点击右上角的叉,或者按下ctrl+c;

 

3、常见问题:

1、如果tomcat启动的时候闪了,就没有了:

解决方案:

  • 启动一个dos,执行启动的命令:

  • 查看日志;其实黑窗口打印的每句话,在日志里面都有;

主要看的是:catalina_日期.log(一天一个);

Localhost:_access_log:每一个人点击访问的信息这里面都有

总结:启动一个tomcat之前,java_HOME必须配置

 

 

2、报以下错误

catalina_日期.log(一天一个)日志中:

java.net.BindException: Address already in use: JVM_Bind

        at java.net.DualStackPlainSocketImpl.bind0(Native Method)

        at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106)

        at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)

        at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:190)

        at java.net.ServerSocket.bind(ServerSocket.java:375)

        at java.net.ServerSocket.<init>(ServerSocket.java:237)

        at org.apache.catalina.core.StandardServer.await(StandardServer.java:438)

        at org.apache.catalina.startup.Catalina.await(Catalina.java:718)

        at org.apache.catalina.startup.Catalina.start(Catalina.java:664)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:498)

        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:349)

        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:483)

解决方案:任何一个程序都不能启动两次(服务器端);每一次启动的那个占用了8080,第二个启动还想占用8080;8080端口已经被使用了

 

4、自带服务介绍

Docs:文档,tomcat提供的文档

Examples:例子  

ROOT:根,三条猫的首页;如果想访问,不能删除,

  1. 访问其它服务

http://192.168.1.2:8080/docs/

Docs:服务名

 

5、访问管理页面

  1. 其中manager和host-manager,需要输入用户名和密码才能访问;

配置用户名和密码:

修改conf/tomcat-users.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.

-->

<tomcat-users xmlns="http://tomcat.apache.org/xml"

              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"

              version="1.0">

<!--

  NOTE:  By default, no user is included in the "manager-gui" role required

  to operate the "/manager/html" web application.  If you wish to use this app,

  you must define such a user - the username and password are arbitrary. It is

  strongly recommended that you do NOT use one of the users in the commented out

  section below since they are intended for use with the examples web

  application.

-->

<!--

  NOTE:  The sample user and role entries below are intended for use with the

  examples web application. They are wrapped in a comment and thus are ignored

  when reading this file. If you wish to configure these users for use with the

  examples web application, do not forget to remove the <!.. ..> that surrounds

  them. You will also need to set the passwords to something appropriate.

-->

<!--

  <role rolename="tomcat"/>

  <role rolename="role1"/>

  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>

  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>

  <user username="role1" password="<must-be-changed>" roles="role1"/>

-->

  <role rolename="manager-gui"/>

  <user username="root" password="root" roles="manager-gui"/>

</tomcat-users>

 

 

管理界面:

 

 6、修改端口

所有的配置项都在conf/server.xml,修改此文件之前一定要备份

修改port="80"

重启tomcat:

http://192.168.1.2/

好处是:80端口可以省略

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值