The thorough solution of Chinese problems in JBoss

Source: Internet
Author: User
Tags character set modify query jboss linux
Solve | The problem | In Chinese when migrating from the WebLogic system to the JBoss system, Chinese stored in the database and XML files appear garbled.
I'm using the Jboss3.0.8jetty version.
This is due to the default Iso-8859-1 Latin character set passed by the variable in JBoss.
My solution is to modify Org.mortbay.jetty.jar directly. This does not have to write a lot of conversion procedures in the program.
First to http://sourceforge.net/project/showfiles.php?group_id=7322, usually called xxxx-src.tar.gz, are source code. I downloaded the jetty-4.2.20rc0-all.
In.. /jboss-3.0.8/server/default/deploy/jbossweb.sar directory, you need to modify the org\mortbay\ in the Org.mortbay.jetty.jar Httprequest.java under HTTP
Here is the Code modification section:
private void Extractparameters ()
{
if (_paramsextracted)
Return
_paramsextracted=true;

if (_parameters==null)
_parameters=new Multimap (16);

Handle query string
String encoding=getcharacterencoding ();
if (encoding==null)
{
No encoding, so use the existing characters.
Anita Modify
Encoding=stringutil.__iso_8859_1;
ENCODING=STRINGUTIL.__GBK;
_uri.putparametersto (_parameters);
}
Else
{
An encoding has been set, so Reencode query string.
String Query=_uri.getquery ();
if (query!=null)
{
Try
{
Anita Modify
Byte[]qbytes=query.getbytes (stringutil.__iso_8859_1);
Byte[]qbytes=query.getbytes (STRINGUTIL.__GBK);
Urlencoded.decodeto (qbytes,0,qbytes.length,_parameters,encoding);
}
catch (Exception e)
{
_uri.putparametersto (_parameters);
}
}
}
Under the section annotated "//anita modify", it is the key replacement part.
It's only a small part of the work now. There is no __GBK method under Stringutil, so we add the code we need.
Under Org\mortbay\util, open Stringutil.java.
What we need to do is add the following code to the source program:
Anita Add for GBK
public static String __GBK;
Static
{
String gbk=system.getproperty ("GBK");
if (gbk!=null)
__GBK=GBK;
Else
{
try{
New String (New byte[]{(Byte)}, "GBK");
__gbk= "GBK";
}
catch (Java.io.UnsupportedEncodingException e)
{
__gbk= "GBK";
}
}
}
After the modification, use ant to perform the compilation package and replace the JBoss Org.mortbay.jetty.jar.

In this way, the Chinese storage problem is solved. What if a boss wants to use the Chinese URL in the address? Let me continue ...
Under Org\mortbay\util, open Uri.java find about 200 lines
public void Seturi (String uri)
{
..................
..................
Complete last State
Switch (state)
{
Case 1:
..................
Case 2:
..................
Case 3:
_dirty= (Mark==maxi);
_encodedpath=uri.substring (Mark);
_path = Java.net.URLDecoder.decode (_encodedpath, "UTF8");
I use the above sentence to replace the following sentence, it can be:)
_path=decodepath (_encodedpath);
Break
Case 4:
..................
Case 5:
..................
}
}

Also compile and package, replacing Org.mortbay.jetty.jar.
This way, if you have a path in which Chinese characters can be successfully resolved.

The above solutions are successful on both WIN2000 and Redhat Linux.
Don't forget to set your character set on Linux
Locate, if it's not the GBK character set, it needs
Export LANG=ZH_CN. GBK
Export LC_ALL=ZH_CN. GBK



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.