火狐firebug中显示
POST http://localhost:8080/U4/crmcustomerAction!findByPage.action?human=**%E8%94%BA%E6%BA%90**
页面
url :"crmcustomerAction!findByPage.action?human=${logUser.name}",
后台代码
session.put("logUser", logUser);
麻烦请问下为什么页面上传的值是乱码呢?英文就没问题
还有一种,Tomcat服务器没设置编码,Tomcat的server.xml文件中
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
末尾的URIEncoding指定UTF-8
试试 request.setCharacterEncoding("UTF-8"); 修改接收格式
Action中加入:
request.setCharacterEncoding("UTF-8");
JSP页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
或用过滤器
url上的中文需要自己手动转换,设置编码格式是没有用的
解决办法:
logUser.name = new String(logUser.name.getBytes("iso-8859-1"), "UTF-8");
乱码无非就三种情况:
1,页面获取的就是乱码,设置页面字符集:<%@page languange = "java" contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
2,服务端的action接收使字符集不一致:request.setCharacterEncoding("utf-8");
3,action接收到的就是乱码,此时就考虑转码了:loginUser.name = new String(loginUser.name.getBytes("ISO-8859-1"),"utf-8");多尝试几重:GBK,
还不行的话就要考虑是不是自己的IDE的字符集设置的问题了,修改为统一的字符集。