jsp - A general tomcat (v7) 404 redirect to external url -


after testing several suggestions (like redirect external website on tomcat), still not able have redirect external url non existing webapps in tomcat.

my situation following:

  • tomcat runs on url localhost
  • a lot of webapps running in directory webapps/app1, webapps/app2, ...
  • a url call on localhost/app1 open app app1
  • a url call on localhost/app2 open app app2
  • a url call on localhost open app1 (automatic redirect configured in tomcat)

my goal achieve redirect external website http://www.test.com/404.html when enters url localhost/asdf. there way can achieve globally in tomcat adding errorpage property in /conf/web.xml?

answered here: how handle not available tomcat 7 webapps

tomcat version = ?

what want?

a. if want redirect non-existent web applications elsewhere, configure error-page in root web application (aka default web application).

the root web application handles requests have not been handled other web applications.

b. if want configure default setting "error 404" handling across web applications:

it rather hard share jsp page between web applications (ymmv), easy share servlet.

  • prepare servlet performs redirection.

    e.g. extend javax.servlet.http.httpservlet , override "service" method. this:

    @override protected void service(httpservletrequest req, httpservletresponse resp)     throws servletexception, ioexception {      // todo: check request.getmethod() 1 of "get", "head", "post"?      response.sendredirect("http://www.test.com/404.html");      //// or if want better control on http status code (302/307/...):     // response.reset();     // response.setstatus(302);     // response.setheader("location", "http://www.test.com/404.html");  } 
  • put code lib directory of tomcat — jar or package/class files tree.

  • configure servlet in conf/web.xml , map onto url there, e.g. /web-inf/404

    <servlet>     <servlet-name>bar</servlet-name>     <servlet-class>foo.bar</servlet-class> </servlet> <servlet-mapping>     <servlet-name>bar</servlet-name>     <url-pattern>/web-inf/404</url-pattern> </servlet-mapping> 
  • configure error-page in conf/web.xml location served servlet.

    <error-page>   <error-code>404</error-code>   <location>/web-inf/404</location> </error-page> 

if not help, 1 can extend errorreportvalve class.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -