Tomcat基本URL重定向
使用tomcat,我如何获得http://www.mydomain.com的请求重定向到http://www.mydomain.com/somethingelse/index.jsp? 我甚至没有设法从http://mydomain.com获得index.html显示。
将您的web应用命名为WAR“ROOT.war”或包含文件夹“ROOT”
你可以这样做:如果你的tomcat安装是默认的并且你没有做任何改变,那么默认的war将是ROOT.war 。 因此,无论您何时调用http://yourserver.example.com/ ,它都会调用默认WAR文件的index.html或index.jsp 。 在您的webapp/ROOT文件夹中进行以下更改,将请求重定向到http://yourserver.example.com/somewhere/else :
打开webapp/ROOT/WEB-INF/web.xml ,删除路径为/index.html或/index.jsp任何servlet映射,然后保存。
删除webapp/ROOT/index.html (如果存在)。
用以下这行内容创建文件webapp/ROOT/index.jsp :
<% response.sendRedirect("/some/where"); %>
或者如果你想直接到不同的服务器,
<% response.sendRedirect("http://otherserver.example.com/some/where"); %>
而已。
看看UrlRewriteFilter,它实质上是Apache的mod_rewrite的基于Java的实现。
您需要将其解压到Tomcat的webapps文件夹下的ROOT文件夹中; 您可以将重定向配置为其WEB-INF/urlrewrite.xml配置文件中的任何其他上下文。
