ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Re: problem with Japanese characters
Posted by Peter Kwan on Sep-30-2004 05:28
Attachments:
Hi Girish,

There are two things you need to check.

1. Make sure the server understands your encodings.

If you can print the Japanese characters, it may only mean that your console can understand what the browser enters. (Is your console a browser, or a display device on the client side, or is it a monitor connected directly to the server?) The server may not understand what the browser enters at all.

From my understanding, no matter what encoding you choose (eg. using pageEncoding directive), the server always uses ISO-8859-1 encoding when interpretating user input. (I am not sure if your Apache SetCharacterEncodingFilter will modify this, but I think it is better just to remove it to avoid confusion.)

Since the browser actually uses UTF8 for input (I assume your pageEncoding works), the standard method is to ask the server to re-interpreted it using UTF8. The code is:

//get query parameter (user input)
String x = (String)request.getParameter("xxx");

//re-interpret as UTF8, assuming the pageEncoding is using UTF8
x = new String(x.getBytes("8859_1"), "utf-8");

One way to ensure the web server interprets the characters correctly is to display the Unicode equivalent of the character:

//prints out the unicode of the first character
c.addTitle("" + ((int)x.charAt(0)));

Then you can look up the "Windows/Accessories/System Tools/Character Map" to check if it is the character you expect. (If it is a Japanese character, the Unicode equivalent should be a number much bigger than 256.) If the Java server really understands the user's input, it should be able to return its unicode equivalent correctly.


2. If you are sure the web server understands the character correctly, then you need to ensure it uses the correct font. For example, if you use the Arial font, then the Japanese characters cannot be displayed, because Arial font does not have Japanese support. (In my computer, I find the "MingLiu" font that supports Japanese. You will need to use a Japanese font that your computer have.)


I have attached a sample code to demonstrate how to process user input in Java. The first line of the code contains "pageEncoding='UTF-8'", which tells the browser to send user input as UTF8. Then the Java code uses the method (1) above to re-interpret the user input as UTF8. Then I use the MingLiU font to display the user input in the chart title. No other server side configuration is necessary.

If you try to run the code, please change the "MingLiU" font to a font that you have.

Regards
Peter Kwan
simplebar.jsp
<%@page import="ChartDirector.*" pageEncoding="UTF-8" %>
<%
//The data for the bar chart
double[] data = {85, 156, 179.5, 211, 123};

//The labels for the bar chart
String[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};

//Create a XYChart object of size 250 x 250 pixels
XYChart c = new XYChart(250, 250);

//get the parameter and convert to UTF8
String x = (String)request.getParameter("xxx");
if (x == null)
	x = "";
else
	x = new String(x.getBytes("8859_1"), "utf-8");

c.addTitle(x, "MingLiU", 14);

//Set the plotarea at (30, 30) and of size 200 x 190 pixels
c.setPlotArea(30, 30, 200, 190);

//Add a bar chart layer using the given data
c.addBarLayer(data);

//Set the x axis labels using the given labels
c.xAxis().setLabels(labels);

//output the chart
String chart1URL = c.makeSession(request, "chart1");

String fullpath= application.getRealPath("/jspdemo/tmpcharts");
String filename = c.makeTmpFile(fullpath);

//include tool tip for the chart
String imageMap1 = c.getHTMLImageMap("", "", "title='{xLabel}: US${value}K'");
%>
<html>
<body topmargin=0 leftmargin=5 rightmargin=0>
<div style="font-size:18pt; font-family:verdana; font-weight:bold">
    Simple Bar Chart
</div>
<hr color="#000080">
<form action="simplebar.jsp">
<input name="xxx">
<input type="submit">
</form>
<br>
<!--img src="getchart.jsp?<%=chart1URL%>" usemap="#map1" border="0"-->
<img src="<%=request.getContextPath() + "/jspdemo/tmpcharts/" + filename%>" usemap="#map1" border="0">

<map name="map1"><%=imageMap1%></map>
</body>
</html>

Current Thread Author Date
problem with Japanese characters Girish Sep-29-2004 12:29
* Re: problem with Japanese characters simplebar.jsp Peter Kwan Sep-30-2004 05:28
Thanks Girish Sep-30-2004 11:36
Re: problem with Japanese characters gantt2.php soma Oct-12-2007 12:44
Re: problem with Japanese characters soma Oct-12-2007 15:31