天天看點

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

這裡使用Web輕量級的伺服器Tomcat

Tomcat常用作servlet的運作容器,在JavaWeb開發中廣泛使用,當然,Tomcat也可為提供HTML頁面服務。

主要步驟:

  1. Tomcat下載下傳安裝
  2. 環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)
  3. 釋出Web應用程式

 1、登入官網下載下傳:https://tomcat.apache.org/download-80.cgi

這裡選擇tomcat8,太高的版本擔心ide會不支援,點選Core》zip下載下傳。

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

解壓後的目錄結構為:

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

還是要安裝一下,不然好像不行

下載下傳,然後也是一路确定。

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式
搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式
搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

 這裡的端口号預設為:8080

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

然後選擇jre的安裝路徑:(怎麼感覺這裡和環境變量配置很像)

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

選擇tomcat安裝路徑(預設):C:\Program Files\Apache Software Foundation\Tomcat 8.5

這個就是tmcat的安裝路徑,留意,copy下來

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

1、右鍵單擊“我的電腦”》屬性》進階系統設定》環境變量》建立》變量名:TOMCAT_HOME,變量值:C:\Program Files\Apache Software Foundation\Tomcat 8.5

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

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的安裝目錄)

1、找到C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin路徑,輕按兩下startup.bat,啟動服務

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

然後會自動彈出服務啟動資訊

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

輸入:http://127.0.0.1:8080

終于出來了,感動!

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

2、現在來看看我們自己的APP

在C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps中建立一個自己的檔案夾My_Servlet

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

在路徑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>      
搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

 這就是我們自己的應用程式!

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

搭建Web部署環境Tomcat下載下傳安裝環境變量配置(TOMCAT_HOME,CATALINA_HOME,CATALINA_BASE)釋出Web應用程式

終于搞定,搭建好了我們自己的第一個應用程式,感動!!!