`

中文字符进行转码

    博客分类:
  • jsp
阅读更多
我是在JSP文件中加了一句编码语句:
<%@ page contentType="text/html;charset=GB2312"%>
<%request.setCharacterEncoding("GB2312"); %>
然后,在程序中对中文字符进行转码:
存入数据库:
name=request.getParameter("name").trim();
name=new String(name2.getBytes("GB2312"),"ISO-8859-1");
从数据库取出:
listname=new String(rs.getString("name").getBytes("ISO-8859-1"), "GB2312");

而且数据库、Tomcat都是用默认的编码。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics