我有一个奇怪的问题,除了我们的错误页面,本地化效果很好。
我正在使用 Stripes 框架、资源包和 JSTL 标记来本地化我的页面。语言环境由 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?
除了 404 或 500 错误发生时,这在任何地方都很好用,它指向我们的错误页面,它在 web.xml 中的配置如下:
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
如果我直接浏览到错误页面,本地化工作正常。例如,如果我已经将语言设置为西类牙语,然后浏览到此 url,该页面将以西类牙语显示:
http://localhost:8080/error.jsp
但是如果我将语言设置为西类牙语然后浏览到:
http://localhost:8080/this-page-does-not-exist-create-a-404-error
出现相同的错误页面,但以英文呈现。
这是为什么,我该如何解决?我到处搜索都没有结果!
我应该补充一点,我已经尝试手动检查 request.getLocale(),它被设置为 en_US。
在设置Locale的代码中,我们还设置了一些 session 属性,“lang”和“country”。
作为解决方法,我发现我可以读取这些属性并重建语言环境,但我首先想知道为什么会发生这种情况。
最佳答案
您的错误页面可能没有通过 Stripes 过滤器。 尝试从您的 404 页面重定向 Stripes 页面。这可能会解决问题。
关于java - tomcat处理错误页面时没有语言环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9223323/