搭建Web部署环境

这里使用Web轻量级的服务器Tomcat

Tomcat常用作servlet的运行容器,在JavaWeb开发中广泛使用,当然,Tomcat也可为提供HTML页面服务。

主要步骤:

  1. Tomcat下载安装
  2. 环境变量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)
  3. 发布Web应用程序

Tomcat下载安装

 1、登录官网下载:https://tomcat.apache.org/download-80.cgi

这里选择tomcat8,太高的版本担心ide会不支持,点击Core》zip下载。

 

解压后的目录结构为:

 

 

还是要安装一下,不然好像不行

下载,然后也是一路确定。

 

 

 这里的端口号默认为:8080

 

然后选择jre的安装路径:(怎么感觉这里和环境变量配置很像)

选择tomcat安装路径(默认):C:\Program Files\Apache Software Foundation\Tomcat 8.5

这个就是tmcat的安装路径,留意,copy下来

 

环境变量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)

1、右键单击“我的电脑”》属性》高级系统设置》环境变量》新建》变量名:TOMCAT_HOME,变量值:C:\Program Files\Apache Software Foundation\Tomcat 8.5

2、设置方法和1类似,右键单击“我的电脑”》属性》高级系统设置》环境变量》新建》变量名:CATALINA_HOME,变量值:C:\Program Files\Apache Software Foundation\Tomcat 8.5(或者输入:%TOMCAT_HOME%,就是JDK的安装目录)

3、设置方法和1类似,右键单击“我的电脑”》属性》高级系统设置》环境变量》新建》变量名:CATALINA_BASE,变量值:C:\Program Files\Apache Software Foundation\Tomcat 8.5(或者输入:%TOMCAT_HOME%,就是JDK的安装目录)

 

发布Web应用程序

1、找到C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin路径,双击startup.bat,启动服务

然后会自动弹出服务启动信息

 

输入:http://127.0.0.1:8080

终于出来了,感动!

 

 

2、现在来看看我们自己的APP

在C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps中新建一个自己的文件夹My_Servlet

在路径C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\My_Servlet\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">

  <display-name>my first java web</display-name>
  <description>
     A java web application for test.
  </description>

</web-app>

在路径C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\My_Servlet\新建文件test.jsp

<%--
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.
--%>
<%@ page session="false" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>java web 环境搭建测试</title>
    </head>

    <body>
        <h3>这是我的第一次搭建的Java web开发环境</h3>
        <br/>
        测试成功!
    </body>

</html>

 

 这就是我们自己的应用程序!

输入:http://127.0.0.1:8080/My_Servlet/test.jsp

终于搞定,搭建好了我们自己的第一个应用程序,感动!!!

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值