日期:2014-05-20  浏览次数:20836 次

中文乱码 hibernate 页面内的取得
在java文件里
string newTitle="";//从页面得到汉字
secResourceName=newTitle;

在显示页面时secResourceName显示类似 %E5%A5;
我试了secResourceName=new String(newTitle。getByte("utf-8"),"utf-8");得到的内容不变,吧utf8换成iso-8859-1得到类似于yy-1的字符。哪位大侠告诉我该怎么处理才对!

------解决方案--------------------
LS说的都试试,乱码问题有时候就是很麻烦,多试几种方法就行了。
------解决方案--------------------
jsp上面加上
<%@ page contentType="text/html;charset=UTF-8"%>

如果java中debug看到是中文。 那么传到页面上应该就会正常显示
------解决方案--------------------
通过server.xml配置看一下:
< Connector
port ="8080" maxHttpHeaderSize ="8192" 
maxThreads ="150" minSpareThreads ="25" maxSpareThreads ="75" 
 enableLookups ="false" redirectPort ="8443" acceptCount ="100" 
connectionTimeout ="20000" disableUploadTimeout ="true" URIEncoding ="gb2312" />
------解决方案--------------------
package com.east.crm.common;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author:East(张栋芳)
 * @date:Jan 1, 2009
 * @content:字符转码的过滤器
 */
public class EncodingFilter implements Filter {

public void destroy() {
// TODO Auto-generated method stub

}

public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)res;
request.setCharacterEncoding("GBK");
response.setContentType("text/htm;charset=GBK");
chain.doFilter(req, res);
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}

}