Issue
web.xml's <error-page>
allows a developer to specify what to return to client in case of some error (either HTTP status or java exception).
But I have 2 different 404 error pages, per locale.
My web application is structured so that all resources for locale A is under path /a/
; resources for locale B under path /b/
.
I'd like to have a localized error page for 404 when trying to access pages under each locale (to be clear, trying to access /a/some-undefined-resource
should return 404 + an error page localized for locale A).
Given other limitations, it is not really possible to deploy 2 separate applications, a.war and b.war for each locale.
How can I serve an error page that depends on original resource requested?
Solution
I ended giving up the idea to use <error-page>
to serve my SPA and used the urlrewrite filter to rewrite URLs to either /a/index.html
or /b/index.html
.
The downside is that now I have two places to edit when I add new routes inside my SPA:
- angular routes (
app-routing.module.ts
), and urlrewrite.xml
.
Besides, if I add a new locale in the future, I'll need to add a new set of rules to cover all my routes.
Also I don't know how this filter will impact my site's performance. Since it is a low traffic project, I'll keep it this way until I find a better solution.
There is an upside too: now those - otherwise legal - requests are served with status 200, and really missing resources are signaled with 404 and no default content included.
Answered By - rslemos