Question

I have a strange problem, where localization is working great, except on our error pages.

I am using the Stripes framework, resource bundles and the JSTL tag to localize my pages. The locale is determined by the Stripes framework. According to the Stripes documentation:

Stripes uses a HttpServletRequestWrapper to makes calls to request.getLocale() and request.getLocales() return only the chosen locale. This means that not only Stripes will use the correct locale without having to re-determine it, but that any other localization tool that relies on request.getLocales should also default to the correct locale. This includes the JSTL fmt:* tags - cool huh?

This works great everywhere except when a 404 or 500 error happens, which directs to our error page, which is configured like this in web.xml:

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

If I browse directly to the error page, localization works fine. For example, if I've already set the language to Spanish, then browse to this url, the page appears in Spanish:

http://localhost:8080/error.jsp

But if I set the language to Spanish and then browse to:

http://localhost:8080/this-page-does-not-exist-create-a-404-error

The same error page appears, but rendered in English.

Why is that, and how do I fix it? I've searched all over with no results!

I should add, I have tried checking request.getLocale() manually, and it is set to en_US.

In the code that sets the Locale, we also set some session attributes, "lang" and "country".

As a work around, I've found I can read these attributes and reconstruct the locale, but I would like to know why this is happening in the first place.

Was it helpful?

Solution 2

It turns out the problem was that Stripes was handling setting the locale, but the error pages were not being passed through the Stripes Dispatcher. The solution was to add the ERROR line below:

<filter-mapping>
    <filter-name>StripesFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <servlet-name>StripesDispatcher</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

OTHER TIPS

Your error page might not be going through Stripes Filter. Try to redirect a Stripes page from your 404 page. That may fix the issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top