【xaoyaofeng】:
或者如上面那个朋友说的那种方法也可以
String name = new String(request.getParameter("name").getBytes("ISO-8859-1"),"gb2312") ;
【hanfengmvp】:
request.setCharacterEncoding("gb2312"); 不是什么时候都管用的,建议两点
1,用filter
2,new String(request.getParameter("password").getBytes("iso-8859-1"),"gbk");
【libin19830213】:
new String(request.getParameter("password").getBytes("iso-8859-1"),"gbk");
放在filter里 效果很好
【jrunner】:
怎么叫不是什么时候都管用?我一般jsp页面之间都弄一个Servlet,在servlet中使用
request.setCharacterEncoding("gb2312");到现在还没出现不能显示的问题!
【yespie】:
很简单,我就不给你贴代码啦,就告诉你方法吧:
你用DreamWare建一个jsp页面,然后查看源代码,最顶的代码就是解决中文问题的啦。
【jrunner】:
他们说有时这样不行啊!不知道为什么啊!他们说说啥时候不行!快点!
【huxinsheng168】:
<%@ page contentType="text/html;charset=gb2312"%>
【chishan911】:
TO:libin19830213(游戏与娱乐)
new String(request.getParameter("password").getBytes("iso-8859-1"),"gbk");
只能将password参数转换为中文,但对于其他得参数都必须这样写,太麻烦了,
如果在filter里写能够重用得代码该怎么写?
我试过在filter里写request.setCharacterEncoding("gb2312")不管用,但jrunner()说在servlet中使用
request.setCharacterEncoding("gb2312");到现在还没出现不能显示的问题!搞不懂到底是哪儿得事?
【owen_dys】:
最好不用GB2312,都用GBK。因为GBK的词库比GB2312的要大很多。
另外把 out.print 改为 out.write(按字符写)。PS:不过如果是通过表单接受参数的话,这个方法好像只对POST方法适用,GET方法显示还是不能正常。
【sunday_hl】:
直接用UTF-8,文件保存类型也选择UTF-8,应该没问题的,最好还加一个Filter
【pragmatic】:
如楼上所说: UTF-8是最佳选择,同时加个过滤器