Getting Japanese Data From DB and Displaying in JSP

Hi,

We have developed several Japanese Web Pages which are getting displayed correctly and also the data input in Japanese gets stored and displayed correctly when the page is re invoked

The problem I am encountering is that when I try to extract Japanese data from a given table in SQL and display it on my JSP page I get nothing but a series of ? marks even though when I run the same query in SQL, the results are being displayed perfectly in Japanese.

I have imported charset="Shift_jis" in my pages. I would be thankful if somebody could help me out.

Regards

[602 byte] By [RichaM] at [2007-9-26 2:45:48]
# 1

Here is a note I posted a while back on the Tomcat mailing list:

After a bunch of trial and error and some help from

Jason Hunter's NEW Servlet Programming (2nd Edition)

Book we finally got our JSPs and Servlets to support

foreign languages.

I'm going to put what we did in this note for anybody

else that may need to do this and ask a related

question at the end.

First, we added the following to the JSPs:

<%@ page

contentType="text/html;charset=UTF-8"

%>

We also added the following to the HTML header in each

JSP:

<meta http-equiv="Content-Type" content="text/html;

charset=UTF-8">

It seems that the JSP page directive will get you an

"out" (a JspWriter) that will ouput UTF-8 encoded

characters. This is needed for everthing that is

translated on the page like labels and headings.

(Our property files have been translate into the

different languages we need and we get the labels and

headings from these files)

The meta tag controls the way the browser returns the

data for the forms we have in our JSPs.

That is all we had to do for the JSPs.

In the Servlets that process the Form data we did the

little trick from Jason's book:

String input = request.getParameter("firstName");

input=new String(input.getBytes("ISO-8859-1","UTF-8");

Now "input" is a String encoded in UTF-8.

If we used this String as the VALUE of an INPUT tag

before we converted it to UTF-8, the JspWriter would

convert it to UTF-8 not knowing that it was already

UTF-8 and expand the String.

<input type="text" name="firstname"

value="<%=input%>">

My question is, is there a Java setting or maybe a

Tomcat setting that will use UTF-8 as the default for

String objects? I'm not so sure that even if we did

default Java to UTF-8 that we would have a better

soultion because not everything we read is UTF-8

encoded.

Hope this helps and

thanks for any ideas.

WynEaston at 2007-6-29 10:28:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hi,If I include "UTF-8" in the charset then the jsp page fails to compile. Why is this so? ( I have jdk 1.3 )Please reply back as soon as possible.Thanks
RichaM at 2007-6-29 10:28:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
What is the specific error message you get when your JSPs won't compile?I didn't have that problem with the servlets or the JSPs.
WynEaston at 2007-6-29 10:28:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...