How to redirect to external website on 404 Tomcat

此生再无相见时 提交于 2020-01-22 00:47:25

问题


I am using spring 3 + Tomcat 7

In web.xml I have defined

<error-page>
    <error-code>404</error-code>
    <location>/filenotfound</location>
</error-page>

But i want to redirect to external url say www.google.com instead of /filenotfound . How can I do that ?


回答1:


I am not sure whether giving the direct url in location will work. But you can put a jsp there and redirect to the url from the jsp.

<error-page>
    <error-code>404</error-code>
    <location>/filenotfound.jsp</location>
</error-page>

filenotfound.jsp

<%@ page language="java" %>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<c:redirect url="http://hotmail.com" />


来源:https://stackoverflow.com/questions/22548217/how-to-redirect-to-external-website-on-404-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!