大家帮帮忙呀,我写了个jsp,里面用了javabean,在windows下我都能用通过jsp写入中文字符,但在linux下写进的是些乱码,这是为什么呀,来

love_mfc 2003-04-22 03:37:43
我的javabean是这样写的:
public class WriteOver {

private String path;
private String something;

private String GBStr;
public WriteOver() {
path=null;
GBStr="";
something = "";
}//constructor
public String GB2Unicode(String s)
{
if (s == null)
return s ;
char[] orig = s.toCharArray() ;
byte[] dest = new byte[orig.length] ;
for(int i = 0;i < orig.length ; i++)
dest[i] = (byte)(orig[i] & 0xFF) ;
try {
ByteToCharConverter toChar = ByteToCharConverter.getConverter("GB2312") ;
return new String(toChar.convertAll(dest)) ;
}catch (Exception e)
{
System.out.println(e) ;
return s;
}
}

public void setPath(String apath){
path=apath;
}

public String getPath(){
return path;

}
public void setSomething (String asomething){
something = asomething;
}
public String getSomething ()
{
return something;
}

public String writeSomething(){
try
{
File f = new File(path);
PrintWriter out = new PrintWriter(new FileWriter(f));

GBStr=GB2Unicode(this.getSomething());
out.print(GBStr + "\n");//主要是这儿我都已转换成GB格式了,但存入文本文件的还是乱码呀,这是为什么?
out.close();
return "1";//scuess write txt
}catch (IOException e){
return "0";//fail to write
//return e.toString();
}

}
}//class writeOver
...全文
19 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
love_mfc 2003-04-22
  • 打赏
  • 举报
回复
是乱吗,这个不起作用呀,上面是我写的javabean实现在在linux下写文本文件
当我写进中文时,里面实际出现的是乱码
aleccheung 2003-04-22
  • 打赏
  • 举报
回复
字符串要进行改变。
乱吗是?还是看不懂的中文?
jsp文件的
<%@ page contentType="text/html;charset=ISO-8859-1"%>
看看吧!

中文从哪里到哪里是乱吗?
love_mfc 2003-04-22
  • 打赏
  • 举报
回复
我现在在linux下编译也还是老样子呀,帮帮我呀
love_mfc 2003-04-22
  • 打赏
  • 举报
回复
不是呀,class是可移的呀,跟这个没有关系呀
海盗2019 2003-04-22
  • 打赏
  • 举报
回复
是不是在linux下编译的?
dongdongshu 2003-04-22
  • 打赏
  • 举报
回复
我这里用的很正常啊~~~
UP

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧