Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Jetty 7/8中设置JSP响应区域设置?_Jsp_Jetty_Locale - Fatal编程技术网

如何在Jetty 7/8中设置JSP响应区域设置?

如何在Jetty 7/8中设置JSP响应区域设置?,jsp,jetty,locale,Jsp,Jetty,Locale,如果我在servlet中以编程方式设置HTTP响应区域设置,如下所示: @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setLocale(SOME_LOCALE); // .. etc } 然后在Jetty 7和更高版本下,任何试图通过表达式${

如果我在servlet中以编程方式设置HTTP响应区域设置,如下所示:

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
{
    response.setLocale(SOME_LOCALE);
    // .. etc
}
然后在Jetty 7和更高版本下,任何试图通过表达式${pageContext.response.locale}读取该语言环境的JSP都将获得服务器的默认语言环境,而不是上面设置的语言环境。如果我使用Jetty 6或Tomcat,它可以正常工作

下面是演示问题的完整代码:

public class MyServlet extends HttpServlet {

    // Use a dummy locale that's unlikely to be the user's default
    private static final Locale TEST_LOCALE = new Locale("abcdefg");

    @Override
    protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws IOException, ServletException
    {
        // Set a known response locale
        response.setLocale(TEST_LOCALE);

        // Publish some interesting locales to the JSP as request attributes for debugging
        request.setAttribute("defaultLocale", Locale.getDefault());
        request.setAttribute("testLocale", TEST_LOCALE);

        // Forward the request to our JSP
        getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
    }
}
和JSP:

<html>
    <head>
        <title>Locale Tester</title>
    </head>
    <body>
        <h2>Locale Tester</h2>
        <ul>
            <li>pageContext.request.locale = '${pageContext.request.locale}'</li>
            <li>default locale = '<%= request.getAttribute("defaultLocale") %>'</li>
            <li>pageContext.response.locale = '${pageContext.response.locale}' (should be '<%= request.getAttribute("testLocale") %>')</li>
        </ul>
    </body>
</html>
Jetty 7返回此信息(错误):


FWIW,我使用Jetty/Tomcat Maven插件进行了上述所有测试。

我通过Jetty邮件列表发现这是Jetty 7中的一个bug,现在已经存在。

如果使用
新语言环境(“ru”,“ru”)
而不是
新语言环境(“abcdefg”)
,会发生什么情况?在这种情况下,我会得到“pageContext.response.Locale='en\u US'(应该是‘ru_ru’)”,换句话说,我仍然有这个问题。
Locale Tester

    pageContext.request.locale = 'en_AU'
    default locale = 'en_US'
    pageContext.response.locale = 'abcdefg' (should be 'abcdefg')
Locale Tester

    pageContext.request.locale = 'en_AU'
    default locale = 'en_US'
    pageContext.response.locale = 'en_US' (should be 'abcdefg')