我安装了基于 Windows 的 Apache Tomcat。该应用程序当前正在监听端口 8080。我想创建一个从端口 80 的根目录到 8080 子目录中托管的站点的重定向。
我不想输入长 URL 来访问网站 (http://servername:8080/subdirectory/index.jsp),而是直接输入 (http://servername) 并将此重定向到端口 8080 上的子目录。
我厌倦了将它添加到 server.xml 中,但不幸的是。
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
我添加了这个:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"/>
我还修改了根目录下的index.jsp为:
<% response.sendRedirect("server:8080/subdir/login.jsp"); %>
我仍然不相信该站点正在 80 上监听,并且在访问根站点“http://sitename:8080”时我没有重定向。任何帮助,将不胜感激。我对 Apache 比较熟悉,但对 Tomcat 不熟悉。
最佳答案
我通过将以下内容添加到 server.xml 来让它工作
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8080" />
我还将其添加到根文件夹中的 index.jsp 中:
<% response.sendRedirect("http://servername:8080/subdir/page.jsp"); %>
这看起来是处理我想要完成的事情的好方法吗?我不介意用户是否看到重定向的 URL。
关于Apache Tomcat 监听多个端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47561913/