---
title: "tomcat 缩短访问项目主页URL"
author: "deejay"
date: "2013-01-05T17:30:54Z"
tags: []
categories: ["开源软件"]
slug: "tomcat-url"
draft: false
lastmod: "2013-01-05T17:49:17Z"
id: 1762789
url: "https://deejay.iteye.com/blog/1762789"
---

将访问ERP主页的地址由http://localhost:8080/erp简化为http://lh/。

1 打开C:\WINDOWS\system32\drivers\etc\hosts文件,修改最后 一行：
127.0.0.1 localhost
把localhost改为其它值如lh.
2 修改tomcat server.xml文件的http端口号为80.如下所示：
<Connector port="80" protocol="HTTP/1.1"  connectionTimeout="20000"  redirectPort="8443"/>。并在host节点里添加<Context path="" docBase="MYROOT" debug="0" reloadable="true" />。
3 在%TOMCAT_HOME%/webapps目录下新建MYROOT文件夹，并在其下新建index.jsp文件，内容如下：
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  </head>
  <body>
	<%
	response.sendRedirect(request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/erp");
	%>
  </body>
</html>
4 完成。

在windows系统localhost是 127.0.0.1的别名。127.0.0.1是回送地址，指本地机，一般用来测试使用。可修改127.0.0.1的别名为lh.

浏览网页服务默认的端口号都是80，因此只要输入网址即可，不用输入“:80”。

tomcat默认访问的是$tomcat/webapps/ROOT目录里的index.jsp页面。可以修改此目录。