?
Solved

Servlet Getting Parameter Value Problem!!!!!!Plz Help!!!!

Posted on 2002-07-15
14
Medium Priority
?
346 Views
Last Modified: 2013-11-24
Hi All,
I have a servlet servlet1,its output is an HTML page, this page (which of course built dynamically within servlet1) has a button which when clicked on it a javascript function(defined in this page)is called, this script draws another html page and call it in a seperate window as a dialog....(the drawing was done using the with and write tags). In this dialog There is a form which has a text field & a submit button,the user inters some data in this field..the data entered in the Arabic language. after entering his data & when submitting the form, another servlet servlet2 called on this form submit. servlet2 need to know the data entered within the field in the dialog. When i get it using
String data = request.getParameter(fieldname);
The data variable has a rabbish letters!!!!
Am sure that the charset for servlet1,servlet2 and the dialog is windows-1256 which is the charset used for both english/arabic.
Notes:
1- If the data that entered was in english, no roblem    
occurs and the parameter value has the correct letters same as the ones entered in the dialog.
2- If the data that entered was a mix of arabic and english letters, the letters in english will be read correctly within servlet2 but the arabic letters      
no.(rabbish).
I dont know how to solve this and what is causing this????
I need to get the correct value of the letters...
Any comment will be very helpful.
Thanx in advance....
samjav
0
Comment
Question by:samjav
  • 7
  • 5
  • 2
14 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 7154273
 What do you mean by saying rubbish? Do you actually see squares or ? instead of the letters or you see unrecognized letters? If the latter is the problem then it is definetely encoding problem and setting your browser's encoding to arabic would help (or try it with different encodings and see which one fits your needs betetr). If you see blank squares or ? instead of letters then I have a workaround for this. Let me know and I will post the code for you.

  Hope it helps.
0
 

Author Comment

by:samjav
ID: 7154322
When i enter ÇÓÊÚáÇã which means "query" the paremeter value is  Ø§Ø³ØªØ¹Ù„اÙ
when i enter ÊÌÑÈÉ which means "test" the paremeter value is تجربة
What do think girionis ?
0
 

Author Comment

by:samjav
ID: 7154332
It seems that this site didnt accept arabic letters, i dont know how to post the letters i got????
They are an arabic letter and ? series.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:girionis
ID: 7154368
 I can see them properly. Just change the encoding from your browser. If you use IE do View... Encoding... Arabic. If you use Opera do View... Encoding... Arabic as well. If you are using Netscape do View... Character Encoding... Arabic

  Hope it helps.
0
 

Author Comment

by:samjav
ID: 7154394
I checked that, and the encoding already setted to Arabic???
0
 

Author Comment

by:samjav
ID: 7154397
Am using IE version 6.0
0
 
LVL 35

Expert Comment

by:girionis
ID: 7154444
 Hmmm... Try adding the following method in one of your programmes:

private StringBuffer entitizeCharacters(String sections)
{
     char [] characters = sections.toCharArray();     // Create a character array.
     int arrayLength = characters.length;
     StringBuffer chars = new StringBuffer();          // will hold all the characters one by one.
     for (int i=0; i<arrayLength; i++)                    // Go through all the characters of the array.
     {
          // This is done in order to avoid the ArrayIndexOutOfBoundsException
          if (i == arrayLength)
               break;

          if ( (128 <= (int) characters[i] && (int) characters[i] <= 160) || ((int) characters[i]) >= 256 )
               chars.append("&#" + (int) characters[i] + ";");
          else
               chars.append(characters[i]);
     }

     return chars;
}          // end entitizeCharacters

  and then do:

String data = request.getParameter(fieldname);
StringBuffer sb = entitizeCharacters(data);
data = sb.toString();

  Tell us if this is working.
0
 

Author Comment

by:samjav
ID: 7156656
I dont know girionis, it seems that there is something wronge in my code....
It didn't work as expected....
Anyway, Thank you for your help ;(
samjav
0
 
LVL 1

Expert Comment

by:laax
ID: 7159006
Try this.
new String(request.getParameter(<FiledName>).getBytes("8859_1"));

Instead of "8859_1" Use your appropriate encoding.

[FYI, I use this for Japanese language.
new String(request.getParameter("Sortid").getBytes("8859_1"),"JISAutoDetect"));
]

Laax.

0
 

Author Comment

by:samjav
ID: 7159022
Hi Laax...
but how can i get my own encoding?
and what do you mean by JISAutoDetect?

0
 
LVL 1

Assisted Solution

by:laax
laax earned 100 total points
ID: 7159176
Use "8859_6" for Arabic....
[Latin/Arabic Alphabet, ISO 8859-6]

Please have a look at http://ietf.org/rfc/rfc2278.txt
for information.
0
 

Author Comment

by:samjav
ID: 7159282
I used it and it converts the letters returned from the parameter as ????????
I tried the entitizeCharacters method posted by girionis above, i call it after getting the parameter as you said:
String data = new String(request.getParameter(fieldName).getBytes("8859_6"));
StringBuffer sb = entitizeCharacters(data);
data = sb.toString();
But, the data string is still ?????????
I dont know what to do ;(?
Anyway, Thank you laax for your help and if you have another comments i will be very thankful...
samjav.

 
0
 
LVL 35

Accepted Solution

by:
girionis earned 100 total points
ID: 7159346
 Well I just tried a very simple and primitive example and guess what... It works fine for me

HTML

<html>
     <body>
          <form action="readArabic.jsp" name="testArabic" method="post">
               <input type="text" value="" name="arabic"/>
               <input type="submit" value="Go"/>
          </form>
     </body>
</html>

JSP

<html>
     <body>
          <%=request.getParameter("arabic")%>
     </body>
</html>

  I have set the encoding to be Arabic ISO-8859-6 in both the HTML and in the JSP page. I am using Opera 6.1 under Windows NT. When I go home I can try it under Linux as well... I have also tried it on Netscape 6.2.3 and it also works fine.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8917372
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- split points between laax and girionis

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
A solution for Fortify Path Manipulation.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 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