Accessing org.apache.struts.Globals.LOCALE_KEY  in javascript func

Posted on 2012-08-15
Last Modified: 2012-08-17
Hi Experts,

I am wondering if there is a way to access org.apache.struts.Globals.LOCALE_KEY from javascript func.

I am working on web app(Struts) with English and Chinese version. There are simple javascript popup error messages and I want to change language depends on locale.

Are there better ways to deal with something like this?

Question by:dkim18
    LVL 86

    Expert Comment

    Write the locale value into the page from the server side so the script can access it. JavaScript runs on the client.

    Author Comment

    how do I write local value from the sever side???
    LVL 86

    Accepted Solution

    <script type="text/javascript">
      var locale=<%=org.apache.struts.Globals.LOCALE_KEY%>;
      alert('The locale is ' + locale);

    Open in new window

    would be a simple scriptlet way

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now