Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 497
  • Last Modified:

Tomcat in Solaris - UTF-8 problem

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
rajesh_bala
Asked:
rajesh_bala
  • 12
  • 7
1 Solution
 
heyhey_Commented:
what eaxctly is the problem ? do you see any error messages ?
0
 
rajesh_balaAuthor Commented:
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
 
heyhey_Commented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rajesh_balaAuthor Commented:
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
 
rajesh_balaAuthor Commented:
I would greatly appriciate ur help, if this could be solved.

best regards
Rajesh
0
 
heyhey_Commented:
post the code.

with a couple of debugging statements you can quickly isolate the problem.
0
 
rajesh_balaAuthor Commented:
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
 
rajesh_balaAuthor Commented:
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
 
heyhey_Commented:
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
 
rajesh_balaAuthor Commented:
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
 
heyhey_Commented:
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
 
rajesh_balaAuthor Commented:
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
 
heyhey_Commented:
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
 
rajesh_balaAuthor Commented:
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
 
rajesh_balaAuthor Commented:
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
 
heyhey_Commented:
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
 
rajesh_balaAuthor Commented:
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
 
rajesh_balaAuthor Commented:
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
 
rajesh_balaAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 12
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now