请求指点一下jsp乱码(初学者) 你在servlet中打印一下吧 应该也是乱码了 试试这样customer.setCustName(new String(request.getParameter("custName").getBytes(),"utf-8")); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 指点指点:指指点点~把body内容再定义为utf-8试试~ 哈哈,都这样一步步走过来的,虽然说不上深层次的原理,但是可以建议几步:1.打断点看看CustomerServlet ,request.getParameter("custName") 等传过来是否乱码2.是的话在post 方法第一行添加req.setCharacterEncoding("utf-8");3.不是的话在跳转之前添加response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); 4.试试吧, 看看这个博客:http://blog.csdn.net/wenjie4892543/article/details/6697326 楼主,我的博客:http://blog.csdn.net/wangbaoyin/article/details/7457087 你项目的编码是什么编码格式,或者说JAVA类文件的编码。是UTF-8吗?还有就是<meta http-equiv="content-type" content="text/html; charset=UTF-8"> 谢谢,我测试了下,这的确是一种解决乱码的方案,不过必须写成这样:customer.setCustName(new String(request.getParameter("custName").getBytes(),"utf-8")); 不好意思,写错了,应该写成这样: customer.setCustName(new String(request.getParameter("custName").getBytes("ISO-8859-1"),"utf-8")); 谢谢,这样不行,我在page 指令中已经声明编码。 导入spring包,在web.xml中加入以下过滤器<filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf8</param-value> </init-param> </filter> 何必大动干戈呢,直接写一个过滤器,解决所有编码问题。如果你是get请求,请把web服务器的编码设置为utf-8,全部统一为utf-8保证无乱码,偶从来都是这么解决的。 谢谢,确实如您1,2部所说,而且通过:request.setCharacterEncoding("UTF-8")解决了乱码问题。 req.setCharacterEncoding( "gbk "); 楼主在servlet中加response.setContentType("text/html;charset=UTF-8");试试 BVT 用什么工具? 调试JBOSS 6.1结果总是说我少一个叫1.0.com.sun.codemodel.JBreak的包 小弟初学java,还望各位帮帮忙。 我用JAVA中的框架mybatis框架时找不到对象 五万条账号和密码导出 JAVA 调用 .NET写的WEB SERVICE的问题(包括无法传递参数,SOAP头验证) 一个java客户端和c服务端通讯的问题 eclipse有关于weblogic service的插件吗? jdbc问题?连接池 Resin怎么配置servlet环境 myeclipse怎么连接数据库? 关于Hibernate与Oracle10g中的触发器问题
把body内容再定义为utf-8试试~
1.打断点看看CustomerServlet ,request.getParameter("custName") 等传过来是否乱码
2.是的话在post 方法第一行添加req.setCharacterEncoding("utf-8");
3.不是的话在跳转之前添加
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
4.试试吧,
还有就是
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
customer.setCustName(new String(request.getParameter("custName").getBytes(),"utf-8"));
customer.setCustName(new String(request.getParameter("custName").getBytes("ISO-8859-1"),"utf-8"));
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf8</param-value>
</init-param>
</filter>
如果你是get请求,请把web服务器的编码设置为utf-8,全部统一为utf-8保证无乱码,偶从来都是这么解决的。
request.setCharacterEncoding("UTF-8")
解决了乱码问题。
response.setContentType("text/html;charset=UTF-8");试试