มาแปะเรื่อง encoding ภาษาไทย + link excel บน tomcat
posted on 21 Dec 2006 15:29 by tumitblog in Java
พี่เปี๊ยกเขียนไว้ว่า "ตัวอักษร ถ้าเป็น Unicode จริงๆ ค่าที่ได้ควรจะอยู่ในช่วง 0xe01 ถึง 0xe59" จบข่าว
การทำ link ไฟล์ xls ของ tomcat ให้เปิดหน้า open ขึ้นมา ทำได้โดยเข้าไปแก้ไฟล์ %TOMCAT_HOME%/conf/web.xml โดยเพิ่ม
การทำ link ไฟล์ xls ของ tomcat ให้เปิดหน้า open ขึ้นมา ทำได้โดยเข้าไปแก้ไฟล์ %TOMCAT_HOME%/conf/web.xml โดยเพิ่ม
xls application/vnd.ms-excel
ลงไปแล้ว restart ลองทำกับ tomcat 5.0 work แต่ถ้าเป็น tomcat plug-in ไม่ work ครับ
ไปแก้ uri ให้ใช้ encoding ของ page โดย เพิ่ม useBodyEncodingForURI="true"maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" />
ที่ใช้แก้ปัญหา method GET ใน display tag ในการ search ภาษาไทย ขอบคุณน้องจื้อครับ
เพิ่มเรื่องแก้ภาษาไทยใน eclipse console อีกเรื่องแล้วกันครับ
To get the Eclipse console to display charactersin an encoding other than your system default encoding,you need to do the following: 1. Set the file encoding on the target VMin the Arguments Tab of the Run dialog ("-Dfile.encoding=UTF-8"). 2. Set the console encoding to match the encoding you set onthe target VM in the Common tab of the Run dialog. 3. Set a console font that supports the characters that you are tryingto display (Window/Preferences/General/Appearance/Debug/Console Font) Hope that helps. James Couball
ตาม link นี้ครับ
มาเพิ่มเติมส่วนของการ download file ชื่อชื่อเป็นภาษาไทยครับ
response.setHeader("Content-Disposition"
, "attachment; filename=\"" + ThaiEncodingUtils.Unicode2ASCII(fileName) + "\"");
ส่วน code ในการแปลงไปมาก็
public static String ASCII2Unicode(String ascii) {
StringBuffer unicode = new StringBuffer(ascii);
int code;
for(int i = 0; i < ascii.length(); i++) {
code = (int)ascii.charAt(i);
if ((0xA1 <= code) && (code <= 0xFB))
unicode.setCharAt( i, (char)(code + 0xD60));
}
return unicode.toString();
}
public static String Unicode2ASCII(String unicode) {
StringBuffer ascii = new StringBuffer(unicode);
int code;
for(int i = 0; i < unicode.length(); i++) {
code = (int)unicode.charAt(i);
if ((0xE01<=code) && (code <= 0xE5B ))
ascii.setCharAt( i, (char)(code - 0xD60));
}
return ascii.toString();
}
อันนี้ copy มาจาก board narisa ขอบคุณครับ
edit @ 16 Mar 2010 10:03:36 by tumit