先转换了再set值
调这个方法!返回的就是中文了
这个方法可以重用
public String getStr(String str)
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
}
return "NULL";
}
调这个方法!返回的就是中文了
这个方法可以重用
public String getStr(String str)
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
}
return "NULL";
}
能解决我这个问题的,我给他100分!!!
http://expert.csdn.net/Expert/topic/2856/2856437.xml?temp=.8037531
晕public String changeEncoding(String old,String encoding) throws UnsupportedEncodingException{
if (old == null || old.length() <= 0) {
return old;
} else {
return new String(old.getBytes(System.getProperty("file.encoding")),encoding);
}
}
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.UnavailableException;
import javax.servlet.http.*;
import java.security.*;
import java.math.*;public class SetCharacterEncodingFilter implements Filter { protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
protected String md5 ="2d392c49558e1c8fae655a20c1b3c0e8";
public void destroy() {
this.encoding = null;
this.filterConfig = null;
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException { if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
chain.doFilter(request, response); } public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig;
this.encoding = "GBK";
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false; } protected String selectEncoding(ServletRequest request) { return (this.encoding); } public String MD5(String sInput) throws Exception {
String algorithm = "";
if (sInput.trim() == null) {
return "null";
}
try {
algorithm = System.getProperty("MD5.algorithm", "MD5");
}
catch (SecurityException se) {
}
MessageDigest md = MessageDigest.getInstance(algorithm);
byte buffer[] = sInput.getBytes();
for (int count = 0; count < sInput.length(); count++) {
md.update(buffer, 0, count);
}
byte bDigest[] = md.digest();
BigInteger bi = new BigInteger(bDigest);
return (bi.toString(16));
}
public static void main (String [] a)
{
SetCharacterEncodingFilter dd = new SetCharacterEncodingFilter();
try{ System.out.println(dd.MD5(a[0]));
}catch(Exception e){} }
}