JavaWeb——Tomcat

文件夹作用
在这里插入图片描述
在这里插入图片描述

配置

在这里插入图片描述

配置启动的端口号

  • tomcat默认端口号:8080
  • mysql默认端口号:3306
  • http默认端口号:80
  • https默认端口号:443
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"/>

在这里插入图片描述
在这里插入图片描述

配置主机名称

  • 默认的主机名为localhost,等价于127.0.0.1
  • 默认网站应用存放位置(即appBase的值):webapps
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

在这里插入图片描述

C:\Windows\System32\drivers\etc

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
等价于
在这里插入图片描述

  • 由上图我们看到http://127.0.0.1:8080和http://localhost:8080访问到的是同一网站。因此我们可以根据host文件中的配置改变ip对应的域名

高难度面试题

谈谈网站是如何进行访问的?

  • 1.输入一个域名;回车
  • 2.检查本机C:\Windows\System32\drivers\etc\hosts配置文件下有没有这个域名的映射
    - 有:直接返回对应的ip地址,这个地址中,有我们需要访问的web程序,可以直接访问
    在这里插入图片描述
    - 没有,去DNS服务器上找,找到就返回对应ip,找不到就返回找不到
    在这里插入图片描述

发布一个web网站

  • 将自己写的网站,放到服务器(Tomcat)中指定的web应用的文件夹(webapps)下,就可以访问了
  • 网站结构:
-- webapps:Tomcat服务器的web目录
	-Root
	-kuangstudy:网站的目录名
		- WEB-INF
			-classes:Java程序
			-lib:web应用所依赖的jar包
			-web.xml:网站的配置文件(当前仅包括该文件)
		- index.html 默认的首页
		- static(资源文件)
			-css
				-style.css
			-js
			-img
		-...
		

在这里插入图片描述

1.再webapps下新建一个kuangstudy文件夹

在这里插入图片描述

2.kuangstudy中包括WEB-INF和静态页面index.html

在这里插入图片描述

3.WEB-INF下包括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"
  metadata-complete="true">

 
</web-app>

4.静态页面index.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.a{
				line-height:80px ;
				float:left;
				border: 1px white solid;
				width: 10%;
				height: 96px;
				margin-left: 1px;
			}
			.b{
				line-height:70px ;
				float:left;
				border: 1px blue solid;
				width: 90px;
				height: 73px;
				margin-left: 95px;
			}
			#head{
				border: 1px white solid;
				height: 96px;
				width: 100%;
			}
			#div1{
				width: 190px;
			}
			#div2{
				background-image: url(picture/logo.png);
				background-size: 100% 100%;
				width: 100px;
			}
			#div3{
				width: 221px;
			}
			#div4{
				width: 290px;
			}
			#div5{
				background-image: url(picture/phone1.png);
				background-size: 100% 100%;
				width: 60px;
			}
			#div6{
				width: 310px;
			}
			#div7{
				width: 100px;
			}
			#t6{
				width: 120px;
			}
			#tixi{
				background-color: blue;
				margin-top: 5px;
				border: 1px white solid;
				height: 75px;
				width: 100%;
			}
			#pic{
				margin-top: 5px;
				width: 100%;
				height: 505px;
				background-image: url(picture/D3901032553CB41599A24F53A15A18C7_22.jpg);
				background-size: 100% 100%;
			}
			#jiuye{
				margin-top: 5px;
				height: 75px;
				width: 100%;
				border: 1px white solid;
				background-color:cadetblue;
			}
			#j1{
				width:250px ;
				height: 74px;
				float: left;
				
			}
			#j2{
				width:100px ;
				height: 74px;
				float: left;
				background-image: url(picture/laba.png);
				background-size: 100% 100%;
			}
			#j3{
				float: left;
				width:120px ;
				height: 74px;
				line-height: 80px;
			}
			#j4{
				float: left;
				width:400px ;
				height: 74px;
				line-height: 80px;
			}
			
			
			#run{
				margin-top: 0px;
				height: 170px;
				width: 100%;
				border: 1px white solid;
			}
			#r1{
				float: left;
				height: 169px;
				width: 240px;
				
			}
			#r2{
				float: left;
				height: 169px;
				width: 420px;
				border: 1px white solid;
				border-bottom-style: dashed;
				border-bottom-color: #000000;
				background-color: skyblue;
				background-size: 100% 100%;
				line-height: 40px;
				line-height: 70px;
			}
			#rr2{
				float: left;
				height: 120px;
				width: 130px;
				
				background-image: url(picture/pao.png);
				background-size: 100% 100%;
				
			}
			#r3{
				float: left;
				height: 169px;
				width: 20px;
				
			}
			#r4{
				
				border: 1px white solid;
				border-bottom-style: dashed;
				border-bottom-color: #000000;
				float: left;
				height: 169px;
				width: 420px;
				
				background-color: purple;
			}
			#rrr2{
				float: left;
				height: 120px;
				width: 130px;
				
				background-image: url(picture/pao.png);
				background-size: 100% 100%;
				
			}
			
			#run1{
				margin-top: 0px;
				height: 115px;
				width: 100%;
				margin-left: 2px;
			}
			#a1{
				float: left;
				height: 114px;
				width: 240px;
				
			}
			
			#a2{
				float: left;
				height: 114px;
				width: 420px;
				background-color: skyblue;
				background-size: 100% 100%;
				line-height: 40px;
				line-height: 50px;
			}
			
			#a3{
				float: left;
				height: 114px;
				width: 20px;
				
			}
			#a4{
				margin-left: 2px;
				float: left;
				height: 114px;
				width: 420px;
				background-color: purple;
				line-height: 40px;
				line-height: 50px;
			}
			
			
			
			#run2{
				margin-top: 17px;
				height: 170px;
				width: 100%;
				border: 1px white solid;
			}
			#b1{
				float: left;
				height: 169px;
				width: 240px;
				border: 1px white solid;
			}
			#b2{
				float: left;
				height: 169px;
				width: 420px;
				border: 1px white solid;
				border-bottom-style: dashed;
				border-bottom-color: #000000;
				background-color: skyblue;
				background-size: 100% 100%;
				line-height: 40px;
				line-height: 70px;
			}
			#rru2{
				float: left;
				height: 120px;
				width: 130px;
				background-image: url(picture/pao.png);
				background-size: 100% 100%;
				
			}
			#b3{
				float: left;
				height: 169px;
				width: 20px;
				border: 1px white solid;
			}
			#b4{
				float: left;
				height: 169px;
				width: 420px;
				border: 1px white solid;
				border-bottom-style: dashed;
				border-bottom-color: #000000;
				background-color: purple;
			}
			#rrru2{
				float: left;
				height: 120px;
				width: 130px;
				
				background-image: url(picture/pao.png);
				background-size: 100% 100%;
				
			}
			
			#run3{
				margin-left: 1px;
				margin-top: 0px;
				height: 115px;
				width: 100%;
				/* border: 1px white solid; */
			}
			#c1{
				float: left;
				height: 114px;
				width: 240px;
				border: 1px white solid;
			}
			#c2{
				margin-left: 1px;
				float: left;
				height: 114px;
				width: 420px;
				background-color: skyblue;
				background-size: 100% 100%;
				line-height: 40px;
				line-height: 40px;
				line-height: 50px;
			}
			
			#c3{
				float: left;
				height: 114px;
				width: 20px;
				border: 1px white solid;
			}
			#c4{
				margin-left: 2px;
				float: left;
				height: 114px;
				width: 420px;
				background-color: purple;
				line-height: 40px;
				line-height: 50px;
			}
		</style>
	</head>
	<body>
		<div id="head" >
			<div id="div1" class="a" >
					
				</div>
				<div id="div2" class="a" >
					
				</div>
				<div id="div3" align="center" class="a" >
					<font size="5" color="black" >西部开源欢迎你!</font>
				</div>
				<div id="div4" class="a" >
					
				</div>
				<div id="div5" class="a" >
					
				</div>
				<div id="div6" align="center" class="a" >
					<font size="5" color="black">029-86699937 029-88262419</font>
				</div>
				<div id="div7" class="a" >
					
				</div>
		</div>
		<div id="tixi">
			<div id="t1" class="b" align="center">
				<font size="4" color="white">首页</font>
			</div>
			<div id="t2" class="b" align="center">
				<font size="4" color="white">课程中心</font>
			</div>
			<div id="t3" class="b" align="center">
				<font size="4" color="white">教学体系</font>
			</div>
			<div id="t4" class="b" align="center">
				<font size="4" color="white">新闻资讯</font>
			</div>
			<div id="t5" class="b" align="center">
				<font size="4" color="white">学习资源</font>
			</div>
			<div id="t6" class="b" align="center" >
				<font size="4" color="white">Linux企业化</font>
			</div>
		</div>
		
		
		
		<div id="pic">
			
		</div>
		
		
		<div id="jiuye">
			<div id="j1" class="jy">
				
			</div>
			<div id="j2" class="jy">
				
			</div>
			<div id="j3" class="jy">
				<font size="5" color="white">就业喜报</font>
			</div>
			<div id="j4" class="jy">
				<font size="3" color="white">祝贺xx同学拿到yy公司offer</font>
			</div>
		</div>
		
		
		
		<div id="run">
			<div id="r1">
				
			</div>
			<div id="r2">
				<div id="rr2">
					
				</div>
				<font size="6" color="">Python全栈开发与大数据分析工程师</font>
			</div>
			<div id="r3">
				
			</div>
			<div id="r4">
				<div id="rrr2">
					
				</div>
				<font size="6" color="">Linux 云自动化运维工程师</font>
			</div>
			<div id="r5">
				
			</div>
		</div>
		
		
		
		
		<div id="run1">
			<div id="a1">
				
			</div>
			<div id="a2" align="center">
				<div id="rru1">
					
				</div>
				<font size="5" color="" >距离【新班】开班仅剩:<br>0000</font>
			</div>
			<div id="a3">
				
			</div>
			<div id="a4" align="center">
				<font size="5" color="" >距离【新班】开班仅剩:<br>0000</font>
			</div>
			<div id="a5">
				
			</div>
		</div>
		
		
		
		
		<div id="run2">
			<div id="b1">
				
			</div>
			<div id="b2">
				<div id="rru2">
					
				</div>
				<font size="6" color="">区块链+网络安全工程师</font>
			</div>
			<div id="b3">
				
			</div>
			<div id="b4">
				<div id="rrru2">
					
				</div>
				<font size="6" color="">Java+Hadoop开发工程师</font>
			</div>
			<div id="b5">
				
			</div>
		</div>
		
		
		
		<div id="run3">
			<div id="c1">
				
			</div>
			<div id="c2" align="center">
				
				<font size="5" color="" >距离【新班】开班仅剩:<br>0000</font>
			</div>
			<div id="c3">
				
			</div>
			<div id="c4" align="center">
				<font size="5" color="" >距离【新班】开班仅剩:<br>0000</font>
			</div>
			<div id="c5">
				
			</div>
		</div>
		
		
		
	</body>
</html>


5.启动Tomcat并访问该网站http://127.0.0.1:8080/kuangstudy

在这里插入图片描述

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值