a.jsp页面通过链接[color=red]href="b.jsp?list=&productname=密度计"[/color],传递参数到b.jsp
我在b.jsp页面通过[color=red]String temp = c.tranC(request.getParameter("productname").trim());[/color]得到参数productname,打印temp显示是"密度?",怎么会出现前面"密度"显示是中文,"计"显示是乱码呢?
我已经在[color=red]conf/server.xml[/color]中的Connector节点中添加属性
[color=red]URIEncoding=“UTF-8"[/color]了。请知道的朋友解答。
部分乱码,应该是GBK和gb2312的编码差异
建议url提交前进行url编码,使用js的 encodeURIComponent编码参数;这样是以utf-8编码的。
这样的话后台tomcat 的配置 如果为URIEncoding=“UTF-8",就可以正常显示;
如果为默认ISO,你需要在java中获取参数转码。
弱弱得问下: c.tranC是干嘛的呀
String name=new String(request.getParamete
("productname").getBytes( "UTF-8"));
试试吧 当时我也因为这个纠结了很久 后来一直用转换的方法 更方便的可以去设置过滤器
还有你先去掉c.tranC 试试 虽然现在不知道它是干嘛的
String name = new String(request.getParameter( "name ").getBytes( "ISO-8859-1"), "UTF-8");
。。你xml中URIEncoding 到底是。。。
URIEncoding只对于get方式提交的参数有效。对于post提交,可以设置filter进行编解码。