JSP中的中文显示为乱码,我该如何是好 加上这个<%@ page language="java" contentType="text/html;charset=gb2312"%> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在页面中加入:<%@ page contentType="text/html;charset=gb2312" %> 针对jsp和servlet:解决办法:第一:在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; } } 关于JAVA WEB开发的一些问题 关于select隐藏一个属性的问题 Jsp的Web开发有类似Asp中母版页的组件吗? 请问:<%! %> 与 <% %> 的区别和使用? 从数据库循环取值的问题,一个简单的问题,请帮忙 在JSP里边怎么动态插入文件 急!!!使用setAutoCommit(false)出错 让我吐血的问题,要疯掉了!有代码……在线等大家帮忙!! 欢迎各位大虾谈一下,您现在用java做什么,Applet or jsp or jdbc? 怎么让我的服务器也支持JSP? 紧急在线等一个很简单的问题 我写的jsp文件出现问题?
<%@ page contentType="text/html;charset=gb2312" %>
解决办法:
第一:
在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;
}
}