解决办法:
第一:
在jsp页面加入:
<%@ page contentType="text/html; charset=gb2312" %>
或者在servlet里面
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=gb2312");
上面的如果在不行就用如下的方法在数据入库前进行调用:
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
第一:
在jsp页面加入:
<%@ page contentType="text/html; charset=gb2312" %>
或者在servlet里面
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=gb2312");
上面的如果在不行就用如下的方法在数据入库前进行调用:
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
解决方案 »
- 问个 关于JNDI 连数据源的问题
- 求高手解救hibernate中Criterion的toSqlString方法
- new Object() 问题(不好意思,只能发100)
- 关于retroguard的问题,请高手指教
- 一个访问sqlserver2000得奇怪问题
- 请问如何通过jdbc获得一个数据库下的所有表名?
- 学习java,要多少时间才可以开发软件啊?
- 异常和返回值的使用场景。
- 谁能告诉我哪里有Borland Optimizeit Profiler V4.11? 急需!
- 请问sqlserver2000的jdbc用于sqlserver7.0行吗??特邀路人甲
- 请问如何才能在Windows环境下,不启动命令窗口来启动Java程序呢?
- 我应该如何书写我的网络路径?
例如: FileInputStream fin= new FileInputStream("java.txt");
FileOutputStream fout= new FileOutputStream("new.txt"); char fint;
//读取前100字节,其中包含中文
for(int i=0;i<100;i++)
{
fint=fin.readChar();
fout.write(fint);//中文能够写到文件中
System.out.println(fint);//显示器显示乱码
}请问why?
部分代码如下:
File inFile = new File("java.txt");
try{
LineNumberReader inputFile = new LineNumberReader(new FileReader(inFile));
while((strVariable=inputFile.readLine())!=null)
{
System.out.println(strVariable); //屏幕上打出
}
}catch(....){.......}