文章目录

  • 一.前言
    • 1.1 准备
  • 二. 搭建
    • 2.1 配置
      • 2.1.1WEB-INF
    • 2.2 启动
    • 2.3 更改端口
  • 三.正常访问

一.前言

根据上篇文章:

Tomcat入门一文详解/精通【javaWeb】

Tomcat服务器是一个免费的开源web应用服务器,它是一个轻量级应用服务器。
我们已经熟悉了Tomcat基本的配置以及使用方法,现在我们来使用Tomca快速搭建一个网站。

1.1 准备

1.Tomcat
2.java环境
3.前端项目源码
关于前端项目我使用之前手写web作业的项目。截图如下:

二. 搭建

2.1 配置

进入Tomcat文件夹,进入

apache-tomcat-10.0.23\webapps

Tomcat默认的webapps会有基本的项目,我们先复制一个文件夹,改文件夹名称为我们的目标文件:

apache-tomcat-10.0.23\webapps\shangjing

删除无用配置文件,留着WEB-INF
注意:
WEB-INF为头文件,不能删除。
如下:

2.1.1WEB-INF

WEB-INF文件夹下的web.xml作用为存储项目的头文件信息等。
我们进入看一下:

<?xml version="1.0" encoding="UTF-8"?>
<!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis 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 withthe License. You may obtain a copy of the License athttp://www.apache/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License. -->

-<web-app metadata-complete="true" version="5.0" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd" xmlns:xsi="http://www.w3/2001/XMLSchema-instance" xmlns="https://jakarta.ee/xml/ns/jakartaee">

<display-name>Welcome to Tomcat</display-name>

<description>Welcome to Tomcat </description>

</web-app>

注意:

<display-name>Welcome to Tomcat</display-name>

<description>Welcome to Tomcat </description>

这俩行可以删除,但是其他不可以删除。

2.2 启动

先到如下路径:

apache-tomcat-10.0.23\bin

找到startup.bat启动项目:

startup.bat


这里因为我没有配置端口等信息,现在是默认的端口信息:

http://localhost:8080/shangjing/

对应文件夹的项目文件夹名称:

访问:

localhost:8080/shangjing/

截图如下:



本前端设计过程如下专栏,有详细的讲解过程。

https://blog.csdn/weixin_52908342/category_11846000.html

2.3 更改端口

更改端口,我们到Tomcat配置文件conf里:

\apache-tomcat-10.0.23\conf

更改server.xml服务器配置文件,将port="8080”
改为我们的目标端口,效果如下:

<Connector port="8888" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

关闭Tomcat,重新启动Tomcat:
再次访问:

http://localhost:8080/shangjing/

无法访问!

访问8888端口:

http://localhost:8888/shangjing/

可以正常访问!

三.正常访问

Tomcat快速搭建网站,目前可以正常访问了,现在这个是纯前端的一个项目。

更多推荐

Tomcat快速搭建网站详解【JAVAWeb】