80端口是比较特殊的端口,是域名默认端口,比如域名是http://www.text.com,将它当成官网的域名,一般直接访问域名即跳出官网的首页,如何设置呢?
比较简单,配置server.xml即可达到目的.
比如有个应用是xny,在server.xml的Host标签下增加如下:
"xny" path="/" reloadable="true" source="org.eclipse.jst.jee.server:LeanFileUpload"/>
设置了xny的应用的访问路径是”/”
当我们访问http://www.text.com域名时后查询访问路径是”/”的应用,这里就是xny.
当存在多个应用是一个tomcat下时,如果还是按如上设置如报”WARNING: A context path must either be an empty string or start with a ‘/’ and do not end with a ‘/’. The path [/] does not meet these criteria and has been changed to []”错误,这时候就不能如上修改server.xml了.
修改webapps/ROOT下的index.jsp文件.
如下
<%
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
request.setAttribute("year", sdf.format(new java.util.Date()));
request.setAttribute("tomcatUrl", "http://tomcat.apache.org/");
request.setAttribute("tomcatDocUrl", "/docs/");
request.setAttribute("tomcatExamplesUrl", "/examples/");
%>
修改成
<%
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
request.setAttribute("year", sdf.format(new java.util.Date()));
request.setAttribute("tomcatUrl", "http://tomcat.apache.org/");
request.setAttribute("tomcatDocUrl", "/docs/");
request.setAttribute("tomcatExamplesUrl", "/examples/");
String contextP = request.getScheme()+"://"+request.getServerName();
String url = contextP + "/xny/index.html";
response.sendRedirect(url);
%>
其实访问根域名进会自动跳转到ROOT应用的index.jsp页面,如果在这里把页面跳转到其它页面也能达到我们的目的,不过有个缺陷,地址url会变成http://www.text.com/xny/index.html
如果有需求访问一个应用跳转的应用在其它域名或tomcat下即可以修改ROOT下的index.jsp实现.
通过阿里云的域名解析.
选择”隐性URL”,记录值不填IP,而是填要跳转的域名
还有一种方式即Nginx代理模式阿里云centos环境之nginx实站配置
总结
算下来最总有4种方式实现标题目的