2011-07-01 12 views
1

私は、サーブレットでプログラムHTTPレスポンスのロケールを設定する場合は、次のように:突堤7の下で続いてJetty 7/8でJSP応答ロケールを設定する方法は?

@Override 
protected void doGet(HttpServletRequest request, HttpServletResponse response) 
    throws IOException, ServletException 
{ 
    response.setLocale(SOME_LOCALE); 
    // .. etc 
} 

を、後に、式$ {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> 

Tomcatが(正確に)これを返します。

Locale Tester 

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

突堤7に戻り、これを(

は、ここで問題を実証するための完全なコードです間違って):

Locale Tester 

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

FWIW、上記のテストはすべてJetty/Tomcat Mavenプラグインを使用して行いました。

+0

''新しいロケール( "abcdefg") 'の代わりに' '新しいロケール(" ru "、" ru ")を使用するとどうなりますか? –

+0

その場合、私は "pageContext.response.locale = 'en_US'( 'ru_RU'にする必要があります)"を取得します。つまり、まだ問題があります。 –

答えて

0

これはJetty 7のバグであることがJettyメーリングリストで分かりました。これは今やbeen fixedです。

関連する問題