JSP with non-English characters

In DB table , I have  I have 3 column
project_id, project_name_english , project_name_japanese
I have records in these columns.

In JSP, I display  records from project_name_english column by default.

Now, I want if my user clicks on "japanese" link on my JSP , I want to display japanese column value.
 I also want if my logged user's language is  "japanese" , then my page should display in japanese.

Question:
What is the best approach I can think here ?

I'm worried about conversion of language.

I'm using JSP, Servlet  and Struts 1.3  mix.
cofactorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Make sure you use UTF-8 encoding in the db and as the page encoding. Then you should be fine
0
cofactorAuthor Commented:
My VO  has 3 fields

String projectID
String projectNameEnglish
String projectNameJapanese

I load data from DB when user logs into the system.  ...and  want to display English by default.

>>> if my user clicks on "japanese" link on my JSP

How do I switch English to Japanese now in JSP ?
0
Pramod KumarCommented:
The field values are stored in ENGLISH or JAPANEES in database?
0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

cofactorAuthor Commented:
>>>The field values are stored in ENGLISH or JAPANEES in database

Database has two separate columns for this.

DBA has loaded  both data manually.
0
CEHJCommented:
Well it's a pretty crude way of arranging things (the project name field should be a key into a language table for example) but check the locale of the client and show the Japanese if it's ja_JP
0
Pramod KumarCommented:
When user click the language link, store the selected lang_key into session. (example: en, jp)
On jsp, check the session value for lang_key and as per that call the respective getter for project name

See my example in jsp:

<%
    String langKey = (String)session.getAttribute("lang");
    ProjectVO proj = (ProjectVO)request.getAttribute("projVo");
%>

Project Name: <%=langKey.equals("en")?proj.getProjectNameEnglish():proj.getProjectNameJapanese()%>

Open in new window

0
JavaGuy78Commented:
Encode your page properly with UTF-8, so that the characters are properly displayed.

Then I would put the english label in a span with a unique ID, then when the user clicks the "Japanese" link or button, run a bit of javascript to rewrite the value in the span with the Japanese value. That way the name is rewritten without the page having to be reloaded.

Something like this:
<span id="projectName">English Title</span>
<input type="button" value="Japanese" onclick="swapProjectName('Japanese title')"/>

<script type="text\javascript">
    function swapProjectName(jTitle) {
        var projectNameSpan = document.getElementById("projectName");
        projectNameSpan.innerHtml = jTitle;
    }
</script>

Open in new window

0
cofactorAuthor Commented:
@pramodkrjsr,

concerns / doubts in your comments.

(1)
If I have to display multiple fields , that becomes a messy code.  Is not there any other simplified way ?

(2) Do I need  to call  javascript reload to reload the page as soon as user clicks on "japanese" link.
0
CEHJCommented:
There are standard, best practices for i18n, which you should follow. No need to reinvent the wheel:

http://www.roseindia.net/struts/strutsinternationalization.shtml
0
cofactorAuthor Commented:
>>>There are standard, best practices for i18n, which you should follow. No need to reinvent the wheel:

they are using multiple properties file ( each property file for each language) whereas  I'll be using database(each column value for each language).

how do you make it dB drivern /?



0
Pramod KumarCommented:
Normally a user will not frequent change the language page to page from english to japaness and vis-versa.

I would suggest to introduce another getter method for project name which will return the value as per language. By this, you need to use only one method in your jsp.

Project Name: <%=proj.getProjectName(langKey)%>
String projectID
String projectNameEnglish
String projectNameJapanese
String projectName;

public String getProjectName(String lagKey)
{
	if(langKey.equals("en")
	{
		return projectNameEnglish;
	}
	else if(langKey.equals("jp")
	{
		return projectNameJapanese;
	}
	return null;
}

Open in new window

0
cofactorAuthor Commented:
Problem with this approach is,  this involves lots of JSP scriplets....code is going to become messy.

I'm looking for a solution with JSTL or Sturts tags.  Can this be made with using JSTL or Struts tags ? Need a small sample to start with.
0
CEHJCommented:
>>how do you make it dB drivern /?

I don't know the answer to that offhand - but there probably is one ;)
0
Pramod KumarCommented:
I don't see lots of JSP scriptlets and just one line for one field:
<%=proj.getProjectName(langKey)%>
0
CEHJCommented:
It would seem the 'proper' way to do it would be to use the new ResourceBundle.Control class to allow the bundle to be loaded from a db. The Javadoc gives clues on this:

http://download.oracle.com/javase/6/docs/api/java/util/ResourceBundle.Control.html
0
cofactorAuthor Commented:
>>>><%=proj.getProjectName(langKey)%>

what is the equivalent code in JSTL ?


>>>>It would seem the 'proper' way to do it would be to use the new ResourceBundle.Control class to allow

Thanks for the info. Will look out for examples.
0
CEHJCommented:
>>Thanks for the info. Will look out for examples.

You might have to be a bit of a pioneer in this field ;)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pramod KumarCommented:

<jsp:useBean id="proj" class="bean.ProjectVO"/>

Project Name: <jsp:getProperty name="proj" property="projectName"/>

Open in new window

0
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.