|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
发信人: gfcae (gfcae), 信区: Java
标 题: Re: 请教一个jsp中文问题
发信站: BBS 水木清华站 (Fri Aug 23 22:18:52 2002), 站内信件
利用下面的方法转换:
-------------------------------------------
- import java.io.*;
- public class TransFormat{
- private static boolean orTrans = true;
- public static String unicodeToGB(String strIn){
- if (orTrans) {
- byte[] b;
- String strOut = null;
- if(strIn == null || (strIn.trim()).equals(""))
- return strIn;
- try{
- b = strIn.getBytes("GB2312");
- strOut = new String(b,"ISO-8859-1");
- } catch (UnsupportedEncodingException e){}
- return strOut;
- } else {
- return strIn;
- }
- }
- public static String GBToUnicode(String strIn){
- if (orTrans) {
- String strOut = null;
- if(strIn == null || (strIn.trim()).equals("")) {
- return strIn;
- }
- try {
- byte[] b = strIn.getBytes("ISO-8859-1");
- strOut = new String(b,"GB2312");
- } catch (Exception e) {}
- return strOut;
- } else {
- return strIn;
- }
- }
- }
复制代码
------------------------------------------------------------------
【 在 junire (我学JAVA的) 的大作中提到: 】
: 我按照书里面讲的在开头加入了charset="gb2312"
: 可以在网页正常显示中文可是如果一写入sql数据库
: 就变成????应该是乱码?
: 请问高手如何解决这个问题,不胜感激。。。
--
Gfcae <gfcae@163.com>
※ 修改:·gfcae 於 Aug 23 22:20:40 修改本文·[FROM: 211.150.235.232]
※ 来源:·BBS 水木清华站 smth.edu.cn·[FROM: 211.150.235.232] |
|