Solved

Tomcat in Solaris - UTF-8 problem

Posted on 2002-06-19
19
484 Views
Last Modified: 2013-12-05
Hi Experts,
   I face a strange problem while deploying a internationalized web application in tomcat 3.3 in solaris machine.
   Its not accepting the UTF-8 characters in solaris version of tomcat. The same code works fine in windows 2000 environment and the user is able to enter UTF-8 characters.
  The jsp also picks up the UTF-8 characters properly in windows environment. But the same code does not work when deployed in solaris environment.
  What could be the problem. Is it anything related to "file.encoding" property set by the JVM.
  Can anyone help me on this.

Thankx in advance
Rajesh
0
Comment
Question by:rajesh_bala
  • 12
  • 7
19 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 7097926
what eaxctly is the problem ? do you see any error messages ?
0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7097934
Hi HeyHey,
  Let me rephrase it.

1. User enters french characters in the text box (html page).

2. At the server side, we store this value in the data base. (This works fine without any problem).


3. In the next page, we display the user entered french characters. (Here is the problem. It displays some junk characters instead of the french characters.).

4. The value displayed is persisted in the session and displayed to the user. It has got no relation to the database.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7097970
1. what code do you use for getting / displaying text
2. can you give me URL so that I can see the problem myslef ?
0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7097980
Sorry heyhey,
  Since we are in the development process, its in VPN. So u would not be able to access it.
  I don't find any problem in the code. The reason being, it works perfectly ok with windows 2000,tomcat 3.3
  The problem is only with solaris 2.6, tomcat 3.3 environment.
0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7097982
I would greatly appriciate ur help, if this could be solved.

best regards
Rajesh
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7097985
post the code.

with a couple of debugging statements you can quickly isolate the problem.
0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7098003
Sorry heyhey...i can't post the entire code. We are using some framework that its complicated. Anyways, i have given some code in the jsp, the way that we use UTF-8 in the jsp.

<%@ page import="javax.servlet.http.HttpUtils"%>
<%@ page contentType = "text/html;charset=UTF-8"%>
<%
     --
     ----
     ----
     ----
     ----
          String forwardingURL = "/cnams/home/Login.jsp";
          response.sendRedirect(response.encodeURL(forwardingURL));

     }
%>


In the serverside, we are using request.readParameter() method.
0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7098007
I have also searched google about this problem. But could not find most relavent data.
Do i need to install any patch for the jvm?...
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7098020
you do not give me enough information to help you solving the problem.

I do not think that this is JavaVM bug - after all we are talking about characters/bytes conversions.

save the raw data (as byte array) in several places in the app and try to find out where exactly is the differnece between Win and Solaris behavior.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 10

Author Comment

by:rajesh_bala
ID: 7101344
Hi heyhey,
  I tried to compare the strings in windows and solaris. The data in both the environments are different.

For ex :
Ü : [B@a6997 : Windows 2000
Ü : [B@58581d  : Solaris 2.6

I tried entering Ü and got the above two results. What could be the next step. Please guide me.

0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 100 total points
ID: 7101348
use

System.out.println(hexDump(buf));

to dump the whole array.

here are the helper methods


  public static String hexDump(byte buf[])
  {
    return hexDump(buf, 0, buf.length);
  }
 
  public static String hexDump(byte buf[], int pos, int len)
  {
    String st = "";
    for (int i = pos; i < len; i++)
    {
      int nn = 0xff & buf[i];
      char nn1 = (char)('0' + (nn >> 4));
      char nn2 = (char)('0' + (nn & 0x0f));
      if (nn1 > '9') nn1 += (65 - 58) + 32;
      if (nn2 > '9') nn2 += (65 - 58) + 32;
     
      st += "<0x" + nn1 + nn2 + ">";
    }
    return st;
  }
0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7101366
Hi,
  I tried the above and got the following results.

 <0xc3><0x9c>  -   "Ü "  (please note that it is followed by a space) - This is in Solaris environment
 <0xdc>  -  in windows environment. Please note that even though i used space with "Ü " it didn't print the value of that..

What is the significance of printing the dump like this. Can u please explain heyhey.




0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7101368
decoded char data on the two machines is different, which IS A PROBLEM.

I lost too much time on that question and I CANNOT HELP YOU IF YOU DON'T SHOW ME YOUR CODE.
0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7101369
Hi,
  I tried the above and got the following results.

 <0xc3><0x9c>  -   "Ü "  (please note that it is followed by a space) - This is in Solaris environment
 <0xdc>  -  in windows environment. Please note that even though i used space with "Ü " it didn't print the value of that..

What is the significance of printing the dump like this. Can u please explain heyhey.




0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7101374
Hi heyhey,
  I got a mail that the question is updated. But when i see the page there is no comments. Can u please repost the comments.

Thankx
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7101376
Comment

From: heyhey_
Date: 06/22/2002 11:43PM PST

decoded char data on the two machines is different, which IS A PROBLEM.

I lost too much time on that question and I CANNOT HELP YOU IF YOU DON'T SHOW ME YOUR CODE.
0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7110107
Hi,
  I could not still correct the problem. I tried setting the locale to "en_US.UTF-8" and then tried. Even that didn't help.
  Anyways..thanks a lot for giving the suggestion at the right time heyhey..

regards
Rajesh
0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7114055
Hi HeyHey,
  I am trying it with the following sample code. The following code is saved as test.jsp.

<%
String tmp=null;
if(request.getParameter("test")!=null)
{
     
     tmp=request.getParameter("test");
     out.println(tmp);
     out.println("<br>BYTES : " + tmp.getBytes());

     String st = "";
   for (int i = pos; i < len; i++)
   {
     int nn = 0xff & buf[i];
     char nn1 = (char)('0' + (nn >> 4));
     char nn2 = (char)('0' + (nn & 0x0f));
     if (nn1 > '9') nn1 += (65 - 58) + 32;
     if (nn2 > '9') nn2 += (65 - 58) + 32;
     
     st += "<0x" + nn1 + nn2 + ">";
   }
}
else
{
     tmp="Sample";
}

System.out.println("On the server end ->"+tmp+"<-");
%>
<META http-equiv="Content-Type" content="text/plain; charset=UTF-8">
Hello
<br>
<form method='POST'>
<input type=text name=test value=<%=tmp%>>
<input type=submit>
</form>
<br>
<br>
<h2>
The text comming is -><%= tmp %><-
</h2>

Now, I enter a japanese character in the text box and submit the form.
Its displayed back correctly.
Please note that it works fine in solaris also.
But when i tried to submit the form again , it bombs. It does not show up the correct data. Can u help me on this?..

0
 
LVL 10

Author Comment

by:rajesh_bala
ID: 7114065
Sorry about the previous code. Please use the following code

<%
String tmp=null;
if(request.getParameter("test")!=null)
{
     
     tmp=request.getParameter("test");
     out.println(tmp);
     out.println("<br>BYTES : " + tmp.getBytes());

     String st = "";
     byte[] buf = tmp.getBytes();
   for (int i = 0; i < buf.length; i++)
   {
     int nn = 0xff & buf[i];
     char nn1 = (char)('0' + (nn >> 4));
     char nn2 = (char)('0' + (nn & 0x0f));
     if (nn1 > '9') nn1 += (65 - 58) + 32;
     if (nn2 > '9') nn2 += (65 - 58) + 32;
     
     st += "<0x" + nn1 + nn2 + ">";
   }
}
else
{
     tmp="Sample";
}

System.out.println("On the server end ->"+tmp+"<-");
%>
<META http-equiv="Content-Type" content="text/plain; charset=UTF-8">
Hello
<br>
<form method='POST'>
<input type=text name=test value=<%=tmp%>>
<input type=submit>
</form>
<br>
<br>
<h2>
The text comming is -><%= tmp %><-
</h2>
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Groovy:unable to resolve class error 2 68
bash while loop reading input from data section in script 7 63
Control Number of Log Files -Perl 7 54
Linux hostname change 2 54
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

911 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

23 Experts available now in Live!

Get 1:1 Help Now