Tomcat base URL redirection

前端 未结 6 2174
太阳男子
太阳男子 2020-11-28 23:00

Using tomcat, how do I get a request for http://www.mydomain.com to redirect to http://www.mydomain.com/somethingelse/index.jsp ? i haven\'t even managed to get an index.htm

6条回答
  •  佛祖请我去吃肉
    2020-11-28 23:13

    You can do this: If your tomcat installation is default and you have not done any changes, then the default war will be ROOT.war. Thus whenever you will call http://yourserver.example.com/, it will call the index.html or index.jsp of your default WAR file. Make the following changes in your webapp/ROOT folder for redirecting requests to http://yourserver.example.com/somewhere/else:

    1. Open webapp/ROOT/WEB-INF/web.xml, remove any servlet mapping with path /index.html or /index.jsp, and save.

    2. Remove webapp/ROOT/index.html, if it exists.

    3. Create the file webapp/ROOT/index.jsp with this line of content:

      <% response.sendRedirect("/some/where"); %>
      

      or if you want to direct to a different server,

      <% response.sendRedirect("http://otherserver.example.com/some/where"); %>
      

    That's it.

提交回复
热议问题