搭建Web部署环境

  1. 云栖社区>
  2. 博客>
  3. 正文

搭建Web部署环境

乌云上 2018-08-01 10:51:00 浏览1389
展开阅读全文

这里使用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/500
评论
乌云上
+ 关注