大家好,今天分享tomcat 服务器
Tomcat 服务器是一个免费的开源代码Web 应用服务器
这是tomcat点击官网。
下面再Windows 在环境中,安装和配置
我用这个版本:(下载后需要解压)
打开tomcat。你可以看到里面的文件
bin: 这是操作它的脚本文件 conf : 这是tomcat 的配置文件 lib : 这里是它的jar包 logs : 这是它的日志文件 webapps:这是存储网站的资源 work : 这是它的工作文件
这里提一下,Windows下的tomcat服务,解压之后就可以使用
但是,启动时可能会遇到闪回问题
点击此文件
注意这两个文件
打开startup.bat (以下是其启动文件)
我们需要这个startup,bat 添加到这个文件中(在这个文件的前面)
SET JAVA_HOME= C:\Users\Administrator\.jdks\corretto-1.8.0_312(java jdk目录) SET JRE_HOME=C:\Users\Administrator\.jdks\corretto-1.8.0_312\jre SET CATALINA_HOME=E:\apache-tomcat-9.0.24-windows-x86\apache-tomcat-9.0.24 # 这是tomcat安装目录(因人而异)
截图是这样的 记得保存
打开shutdown.bat这个文件
在这个文件的第一行加上
SET JAVA_HOME= C:\Users\Administrator\.jdks\corretto-1.8.0_312 SET JRE_HOME=C:\Users\Administrator\.jdks\corretto-1.8.0_312\jre SET CATALINA_HOME=E:\apache-tomcat-9.0.24-windows-x86\apache-tomcat-9.0.24
记得保存
点击startup.bat这个文件 可以dos窗口以前台的形式运行(这是正常的)
如果我们刚刚没有配置相应的环境变量,这个地方就会闪回
这将导致启动失败
我们已经成功启动了tomcat 服务器
我们现在使用浏览器访问tomcat服务器 (http://localhost:8080/)
在我们进行网页访问的时候,startup.bat 文件的前台进程不可以断掉
否则浏览器的访问将出现问题:
这是关掉
再次运行:
这样就访问正常
也可以通过shutdown.bat 这个文件来关闭服务器
再次使用startup.bat 这个文件 来启动tomcat服务器
现在可以正常访问
这个文件是tomcat服务器非常重要的配置文件
这就是这个配置文件里所有的东西
<?xml version="1.0" encoding="UTF-8"?><!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation. The default
SSLImplementation will depend on the presence of the APR/native
library and the useOpenSSL attribute of the
AprLifecycleListener.
Either JSSE or OpenSSL style configuration may be used regardless of
the SSLImplementation selected. JSSE style configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
type="RSA" />
</SSLHostConfig>
</Connector>
-->
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
This connector uses the APR/native implementation which always uses
OpenSSL for TLS.
Either JSSE or OpenSSL style configuration may be used. OpenSSL style
configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
maxThreads="150" SSLEnabled="true" >
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
certificateFile="conf/localhost-rsa-cert.pem"
certificateChainFile="conf/localhost-rsa-chain.pem"
type="RSA" />
</SSLHostConfig>
</Connector>
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
这是我们默认指定的端口
这一行要注意一下
这里有5个web应用,我们要注意ROOT 这个文件
这就是首页的网页资源
注意这个文件
这就是index.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" %>
<%
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
request.setAttribute("year", sdf.format(new java.util.Date()));
request.setAttribute("tomcatUrl", "https://tomcat.apache.org/");
request.setAttribute("tomcatDocUrl", "/docs/");
request.setAttribute("tomcatExamplesUrl", "/examples/");
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title><%=request.getServletContext().getServerInfo() %></title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="tomcat.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="navigation" class="curved container">
<span id="nav-home"><a href="${tomcatUrl}">Home</a></span>
<span id="nav-hosts"><a href="${tomcatDocUrl}">Documentation</a></span>
<span id="nav-config"><a href="${tomcatDocUrl}config/">Configuration</a></span>
<span id="nav-examples"><a href="${tomcatExamplesUrl}">Examples</a></span>
<span id="nav-wiki"><a href="https://wiki.apache.org/tomcat/FrontPage">Wiki</a></span>
<span id="nav-lists"><a href="${tomcatUrl}lists.html">Mailing Lists</a></span>
<span id="nav-help"><a href="${tomcatUrl}findhelp.html">Find Help</a></span>
<br class="separator" />
</div>
<div id="asf-box">
<h1>${pageContext.servletContext.serverInfo}</h1>
</div>
<div id="upper" class="curved container">
<div id="congrats" class="curved container">
<h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>
</div>
<div id="notice">
<img src="tomcat.png" alt="[tomcat logo]" />
<div id="tasks">
<h3>Recommended Reading:</h3>
<h4><a href="${tomcatDocUrl}security-howto.html">Security Considerations How-To</a></h4>
<h4><a href="${tomcatDocUrl}manager-howto.html">Manager Application How-To</a></h4>
<h4><a href="${tomcatDocUrl}cluster-howto.html">Clustering/Session Replication How-To</a></h4>
</div>
</div>
<div id="actions">
<div class="button">
<a class="container shadow" href="/manager/status"><span>Server Status</span></a>
</div>
<div class="button">
<a class="container shadow" href="/manager/html"><span>Manager App</span></a>
</div>
<div class="button">
<a class="container shadow" href="/host-manager/html"><span>Host Manager</span></a>
</div>
</div>
<br class="separator" />
</div>
<div id="middle" class="curved container">
<h3>Developer Quick Start</h3>
<div class="col25">
<div class="container">
<p><a href="${tomcatDocUrl}setup.html">Tomcat Setup</a></p>
<p><a href="${tomcatDocUrl}appdev/">First Web Application</a></p>
</div>
</div>
<div class="col25">
<div class="container">
<p><a href="${tomcatDocUrl}realm-howto.html">Realms & AAA</a></p>
<p><a href="${tomcatDocUrl}jndi-datasource-examples-howto.html">JDBC DataSources</a></p>
</div>
</div>
<div class="col25">
<div class="container">
<p><a href="${tomcatExamplesUrl}">Examples</a></p>
</div>
</div>
<div class="col25">
<div class="container">
<p><a href="https://wiki.apache.org/tomcat/Specifications">Servlet Specifications</a></p>
<p><a href="https://wiki.apache.org/tomcat/TomcatVersions">Tomcat Versions</a></p>
</div>
</div>
<br class="separator" />
</div>
<div id="lower">
<div id="low-manage" class="">
<div class="curved container">
<h3>Managing Tomcat</h3>
<p>For security, access to the <a href="/manager/html">manager webapp</a> is restricted.
Users are defined in:</p>
<pre>$CATALINA_HOME/conf/tomcat-users.xml</pre>
<p>In Tomcat 9.0 access to the manager application is split between
different users. <a href="${tomcatDocUrl}manager-howto.html">Read more...</a></p>
<br />
<h4><a href="${tomcatDocUrl}RELEASE-NOTES.txt">Release Notes</a></h4>
<h4><a href="${tomcatDocUrl}changelog.html">Changelog</a></h4>
<h4><a href="${tomcatUrl}migration.html">Migration Guide</a></h4>
<h4><a href="${tomcatUrl}security.html">Security Notices</a></h4>
</div>
</div>
<div id="low-docs" class="">
<div class="curved container">
<h3>Documentation</h3>
<h4><a href="${tomcatDocUrl}">Tomcat 9.0 Documentation</a></h4>
<h4><a href="${tomcatDocUrl}config/">Tomcat 9.0 Configuration</a></h4>
<h4><a href="https://wiki.apache.org/tomcat/FrontPage">Tomcat Wiki</a></h4>
<p>Find additional important configuration information in:</p>
<pre>$CATALINA_HOME/RUNNING.txt</pre>
<p>Developers may be interested in:</p>
<ul>
<li><a href="https://tomcat.apache.org/bugreport.html">Tomcat 9.0 Bug Database</a></li>
<li><a href="${tomcatDocUrl}api/index.html">Tomcat 9.0 JavaDocs</a></li>
<li><a href="https://svn.apache.org/repos/asf/tomcat/tc9.0.x/">Tomcat 9.0 SVN Repository</a></li>
</ul>
</div>
</div>
<div id="low-help" class="">
<div class="curved container">
<h3>Getting Help</h3>
<h4><a href="${tomcatUrl}faq/">FAQ</a> and <a href="${tomcatUrl}lists.html">Mailing Lists</a></h4>
<p>The following mailing lists are available:</p>
<ul>
<li id="list-announce"><label><a href="${tomcatUrl}lists.html#tomcat-announce">tomcat-announce</a><br />
Important announcements, releases, security vulnerability notifications. (Low volume).</label>
</li>
<li><a href="${tomcatUrl}lists.html#tomcat-users">tomcat-users</a><br />
User support and discussion
</li>
<li><a href="${tomcatUrl}lists.html#taglibs-user">taglibs-user</a><br />
User support and discussion for <a href="${tomcatUrl}taglibs/">Apache Taglibs</a>
</li>
<li><a href="${tomcatUrl}lists.html#tomcat-dev">tomcat-dev</a><br />
Development mailing list, including commit messages
</li>
</ul>
</div>
</div>
<br class="separator" />
</div>
<div id="footer" class="curved container">
<div class="col20">
<div class="container">
<h4>Other Downloads</h4>
<ul>
<li><a href="${tomcatUrl}download-connectors.cgi">Tomcat Connectors</a></li>
<li><a href="${tomcatUrl}download-native.cgi">Tomcat Native</a></li>
<li><a href="${tomcatUrl}taglibs/">Taglibs</a></li>
<li><a href="${tomcatDocUrl}deployer-howto.html">Deployer</a></li>
</ul>
</div>
</div>
<div class="col20">
<div class="container">
<h4>Other Documentation</h4>
<ul>
<li><a href="${tomcatUrl}connectors-doc/">Tomcat Connectors</a></li>
<li><a href="${tomcatUrl}connectors-doc/">mod_jk Documentation</a></li>
<li><a href="${tomcatUrl}native-doc/">Tomcat Native</a></li>
<li><a href="${tomcatDocUrl}deployer-howto.html">Deployer</a></li>
</ul>
</div>
</div>
<div class="col20">
<div class="container">
<h4>Get Involved</h4>
<ul>
<li><a href="
标签: mawomatic传感器h4