Author: Zhou Hagen (dev2dev forum id: zhouhg) Great Wall Software Systems, Inc. J2EE Architect, Project Manager
Chinese issues in web applications 1. Static page Chinese information cannot be displayed correctly
See Chinese can't display correctly. You should check if the browser supports Chinese. The browser is encoded to be correct. To ensure that the static page Chinese information is correctly displayed in the HTML
section:2. Chinese prompt information in JSP does not display correctly
The Chinese prompt information in JSP cannot be displayed normally. The most direct reason is that WebLogic's default character set is not a Chinese character set (WebLogic8.1 is setlocal, webLogic7.0sp3, SP4 is UTF-8), so it can be set in the JSP page. The character set, add the following script:
<% @ page contenttype = "text / html; charset = GBK"%>
This approach needs to be set for each JSP page. The following is set for all JSP pages, which is relatively universal.
3. The prompt information in the JSP file cannot be compiled correctly.
The prompt information in the JSP file is compiled correctly, and you can set the following script in WebLogic.xml, and you can solve the second problem mentioned above:
jsp-param>
jsp-param>
jsp-param>
jsp-descriptor>
4. The Chinese data cannot be passed correctly between JSP files.
Chinese data cannot be passed correctly between JSP files, and there are two ways to solve.
One: Plus the following script in web.xml:
context-param>
2: In WebLogic.xml, add the following script:
input-charset>
charset-params>
Of course, this problem can also handle themselves with java.net.urlencoder and java.net.urldecoder.
There is no database operation involving the above, so analyzing when there is garbled,
It will be possible to find the problem. In addition, you may need to modify the character set of the operating system where the WebLogic application server is located, ensuring Chinese.
Chinese issues in the file name and directory
What if your file name or directory is Chinese? The method mentioned above cannot solve your problem. You need to use java.net.urlencoder encoding. For example, in Test.JSP, you need to provide one The hyperlink is received ./ Test / Test .jsp, you can write this:
Chinese problem in jdbc
If the above method does not solve your garble problem, it may be a mistake in JDBC operation. Here is the Chinese problem in JDBC as an example. First query the database:
Select * from v where parameter = 'nls_characterset';
Get the character set of the database, if ZHS16GBK, the JDBC's operation does not require transcoding; if it is US7ASCII, you need to transfer or related configuration. Below to use different database drivers to describe it.
1. Use Thin Driver
If you use Thin Driver, you need to convert the character set by ISO to GBK when you query the database, and convert the character set by GBK to ISO.
for example:
Insert a record:
Connection conn = NULL;
PreparedStatement PSTMT = NULL;
Try {
String strsql = "INSERT INTO TABA (A, B) VALUES ('1111', 'Wang Chao')"
CONN = ds.getConnection ();
STRSQL = New String (strsql.getbytes ("GBK"), "ISO-8859-1");
PSTMT = conn.preparestatement (strsql);
PSTMT.ExecuteUpdate ();
}
Catch (Exception E) {
//logger. error(E, e);
}
Finally {
Disconn (CONN, PSTMT);
}
Query a record:
Connection conn = NULL;
PreparedStatement PSTMT = NULL;
ResultSet RS = NULL;
Try {
String strsql = "SELECT B from Taba Where A = '1111'";
CONN = ds.getConnection ();
STRSQL = New String (strsql.getbytes ("GBK"), "ISO-8859-1");
PSTMT = conn.preparestatement (strsql);
RS = pstmt.executeQuery ();
String strb;
IF (rs.next ()) {
Strb = new string (rs.getstring (1) .Getbytes ("ISO-8859-1"), "GBK");
}
Catch (Exception E) {
//logger. error(E, e);
}
Finally {
Disconn (CONN, PSTMT, RS);
}
Here, you recommend that you set the Oracle character set in the properties file, determine according to character set
Whether it is transcoding to increase the portability of the application.
2. Using OCI Driver
Use the Driver provided by WebLogic to set the Properties property when configuring the connection pool:
WebLogic.codeset = GBK, as shown below:
When you use the above two ways, you can't solve your garbled code, you check if you are just a lonely word, you can't display it normally? This situation you need to use Oracle's character set: NLS_Charset12.zip, join the package To WebLogic ClassPath. Encrypted Chinese Issues
For encryption and decoding without Chinese information, I want a lot of algorithms to be implemented. However, because Chinese is two characters, ordinary encryption algorithms cannot be restored after a decryption is encrypted. The BASE64 is encoded after encoding Chinese information and encoded. Easily solve this problem. Of course, you also need to decode with Base64 after decryption. Examples are as follows:
String Pw = "Chinese";
System.out.println (PW);
PW = new sun.misc.base64encoder (). Encode (pw.getbytes ());
System.out.println (PW);
//encryption
String pw1 = encode (pw);
System.out.println (PW1);
// Decryption
String PW2 = DECODE (PW1);
System.out.println (PW2);
Byte [] bt = new sun.misc.base64decoder (). DecodeBuffer (PW2);
PW2 = new string (bt);
System.out.println (PW2);
Here is a complete source code encrypted using the Kaiser algorithm:
Package test;
/ **
* Encryption class
* /
Import java.lang.math;
Public class securityTest {
Interface constants {
Public Static Final INT INT_PRIM_NUMBER = 95;
Public static final int tent_return_loop = 94;
}
/ **
* Sysbean constructor commerss.
* /
Public securityTest () {
Super ();
}
/ **
* Decryption method
* zhg
* Create a date (2002-12-15 10:17:08)
* Strcode needs to decrypt strings
* String after decryption
* 1.0
* /
Public static string decode (String strcode) {
String StrorIn;
Int in;
String strrnd;
Int intestrlen;
String strdecodeMe = ""
IF (strcode.equals (")) Return strDecode; INTSTRLEN = STRCODE.LENGTH () - 1;
strRnd = strCode.substring (intStrLen / 2, intStrLen / 2 1); intRnd = strRnd.hashCode () - new SecurityTest () startChar (); strCode = strCode.substring (0, intStrLen / 2) strCode.substring. (intStrLen / 2 1, intStrLen 1); strOriginal = new SecurityTest () loopCode (strCode, Constants.INT_RETURN_LOOP - intRnd);.. strDecodeMe = strOriginal; return strDecodeMe;} / *** acquired encrypted random encryption cycle The number of times makes each encrypted secret article vary * zhg * creation date (2002-12-15 10:08) * StructRiginal needs to encrypt string * Encrypted string * 1.0 * / public static string Encode (String Stroriginal) {String Strcode; Int Intrlen; String Strcode = "; if (StructRiginal.equals (")) Return Strcode; // 2 to 93 The number of times, the same Original article may get 93 different secrets intrnd = (int) (constants.int_return_loop - 2) 2); strcode = new securityTest (). Loopcode (Stroriginal, Intrn); //) offset for encryption rnd = (char) (intRnd new SecurityTest () startChar ().); intStrLen = strCode.length (); strCodeMe = strCode.substring (0, intStrLen / 2) rnd strCode.substring (intStrLen / 2, INTSTRLEN); if (strcode.indexof) '")> = 0) Return Encode (Structurn); Elsereturn StrCodeMe;} // Basic Caesar Alga Algorithm, increasing offset Private String Kaisercode (String Stroriginal) {Int IntChar; String Strcode; INT i INT INTSTRLEN; INT INTTMP; INTSTRLEN = Structure.Length ();
Strcode = ""; for (i = 0; I Summary This article lists some of the Chinese issues that often encounters in WebLogic. I hope the reader can be flexible. Need to remind the GBK character set is bigger than the gb2312 flexible, some are not commonly used in GB2312. So please try Use the GBK character set.