java - MessageResources weird behaviour -


I have a web application for multilingual purpose I use Java Straps 1.3 from MessageResources I am The default language is Italian ( MessageResources.properties ) and the second language is English ( MessageResources_en.properties ).

struts-config.xml :

   

- Message processing - & gt; & Lt; Message-processing parameter = "message processing" />

In my index.jsp :

  & lt;% string language = request.getLocale (). GetLanguage (); & Gt%; Var lang = '& lt;% = language% & gt;'; & Lt; Script type = "text / javascript" src = "js / language.js" & gt; & Lt; / Script & gt; In   

js / language.js :

  $ (document) .ready (function () {var browser = null; Var val = navigator.userAgent.toLowerCase (); if (val.indexOf ("firefox")> gt; -1) browser = 'firefox'; and if (val.indexOf ("msie")> gt; -1) Browser = 'IE'; else if (val.indexOf ("chrome") gt; -1) browser = 'chrome'; $ .ajax ({url: "set default language.", Data: "isolingua =" + lang + "& Browser =" + browser + "& val =" + val, success: function (response) {}});});   

SetDefaultLanguage.java :

  // parametro del browser = (request.getParameter ("isolingua") =! Zero ) {Isolingua = request.getParameter ("Icing"); Switch (isolingua) {case "en": request.getSession (). SetAttribute ("Language", 2); Locale.setDefault (Locale.ENGLISH); Request.getSession () SetAttribute (Globals.LOCALE_KEY, Locale.ENGLISH); System.out.println ("Case N:" + LocalGet Default () + "-" + request.getSession (). GetAttribute (Globals.LoKele_KEE)); break; "This" case: request.getSession (). SetAttribute ("language", 1); Locale.setDefault (Locale.ITALIAN); Request.getSession () SetAttribute (Globals.LOCALE_KEY, Locale, Italian); System.out.println ("Case IT:" + local.get default () + "+" request. Get session (). GetAttribute (globals.locale_keyi)); break; Default: request.getSession (). SetAttribute ("language", 1); Locale.setDefault (Locale.ITALIAN); Request.getSession () SetAttribute (Globals.LOCALE_KEY, Locale, Italian); System.out.println ("case default:" + local.get default () + "-" + request.getSession (). GetAttribute (globals.logge_keae)); break; }}   

Setting the browser language as "Italian" always prints the case: this - but it's strange behavior here: My index, registration or password pages can be found < / P

  • Get all the Italian
  • Passwords and registration in Italian
  • Only a few words in Italian and all the passwords and registration in English < / Li>
  • ... when I restart the Tomcat then

    Other information:

    • Application after login appears to be safe from this weird problem < Li> The application is hosted in a virtual server with the English OS
    • When I try to apply on my local PC (with the Italian OS) this problem may not be
    • request.getSession (). SetAttribute ("lingua", ) is used in servlets to obtain information in DB in the correct language; It always works correctly

      Thank you

      The reason for this is that you use the Locale.setDefault () what the doctor says:

      Java sets the default locale for this example of a virtual machine.
      ...
      Since changing the default locale may affect many different areas of functionality, this method should be used only when the caller is using locale-sensitive code running within a single Java virtual machine Ready to start again

      Typically, to change a location, setting the session attribute Globals.LOCALE_KEY and you can use the code to save the locale

        // Extract Features We will need HTTP session session = request.getSession (); // Get the location from the request, if a local locale = request.getLocale (); // If supplied, set the locale based on request parameter string language = request.getParameter ("isolingua"); If (language! = Null & amp; languages. Langhe ()> gt; {switch (language) {case "en": locale = locale.ENGLISH; Session.setAttribute ("Lingua", 2); break; Default: Locale = Locale. Italian; Session.setAttribute ("Lingua", 1); break; }} // save local session.SetAttribute (Globals.LOCALE_KEY, Locale);    

  • Comments

    Popular posts from this blog

    java - ImportError: No module named py4j.java_gateway -

    python - Receiving "KeyError" after decoding json result from url -

    .net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -