给你一个JavaBean:
/**
* Title: 含有中文的字符串转换成能正常显示中文的字符串
*
* Description: --beans scope 推荐: "page"或"application"
*
**/public class tranChinese
{
public String toChinese(String s)
{
if (s != null)
{
try
{
return new String(s.getBytes("iso-8859-1"), "GB2312");
}
catch (java.io.UnsupportedEncodingException e)
{
System.out.println(e.toString());
}
}
return s;
}public String toUnicode(String s)
{
if (s != null)
{
try
{
return new String(s.getBytes("GB2312"), "iso-8859-1");
}
catch (java.io.UnsupportedEncodingException e)
{
System.out.println(e.toString());
}
}
return s;
}
}
/**
* Title: 含有中文的字符串转换成能正常显示中文的字符串
*
* Description: --beans scope 推荐: "page"或"application"
*
**/public class tranChinese
{
public String toChinese(String s)
{
if (s != null)
{
try
{
return new String(s.getBytes("iso-8859-1"), "GB2312");
}
catch (java.io.UnsupportedEncodingException e)
{
System.out.println(e.toString());
}
}
return s;
}public String toUnicode(String s)
{
if (s != null)
{
try
{
return new String(s.getBytes("GB2312"), "iso-8859-1");
}
catch (java.io.UnsupportedEncodingException e)
{
System.out.println(e.toString());
}
}
return s;
}
}
解决方案 »
- jsoup问题请高手指点
- Struts2.0配置问题
- 紧急求助,关于GWT布置上tomcat的问题
- JSP传值出现乱码问题
- 关于用myeclipse开发网站的问题??
- http://localhost:8083/WebModule1/HtmlBasic.do?prop1=abc&prop2=123,这里面的参数在action中如何取?
- <link href="/template/css/main_style.css" rel="stylesheet" type="text/css"/> 在servlet中怎寫才是正確的呢?
- 给formbean中的变量赋值后,在jsp中能自动显示出来吗?
- jsp参数传递加密的问题
- 紧急求救:在做Model II的例子时候遇到了问题,(在线等待,立刻给分)
- jspsmart和servlet如何结合?
- 我想学JSP,请各位提提建议,好让我少走弯路。
<%@page contentType="text/html;charset=gb2312"%>
String str = new String(str1.getBytes("iso-8859-1");"gb2312");
%>