在工作的过程中遇到了这个问题,尝试了很多办法都没有实现,最后通过下面介绍的方法实现了。现在就给大家介绍一下如何实现通过IP地址直接访问tomcat中应用。
之前从网上查询了很久,试过了修改regedit文件值,没有效果,尝试修改server.xml文件,修改该部分
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="你的项目名" debug="0" reloadable="true"/>
结果无效,依旧无法实现目的。
最后尝试将/webapps/root/下文件删除,重新编写一个html跟jsp去实现这个目的。
删除ROOT文件中的内容,创建一个index.html文件,将下列代码复制过去,修改项目html所在路径,该路径以webapps为根目录,修改完后保存。
<!--
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.
-->
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body>
<meta http-equiv="refresh" content="1;url=项目html地址"></body>
</html>
再创建一个名为index.jsp文件,进入文件编辑,将下列代码复制保存。
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%response.sendRedirect("/portal"); %>
此时,修改server.xml文件中的端口即可。
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />