讨论:JSP 通过URL传递汉字,为奇数个,最后一个为乱码?为偶数个,则正常显示?
寻求最佳解决方案!!
寻求最佳解决方案!!
解决方案 »
- struts2中Action在URL中显示的问题
- 问几个参数传递的问题
- 重分悬赏,这个为题是在解决不了了,hibernate,PrimaryKeyJoinColumn列好像即是主键又是外键,然后插入数据
- DWZ怎么集成第三方插件啊
- JSP中怎么截取字符串??
- Eclipse里面怎样直接看.class文件要装什么插件吗?
- servlet 简单问题?
- 很急的问题
- Servlet连接数据库时,Junit测试正常,Servlet的service报错,求指点
- 求助——错误:org.hibernate.exception.SQLGrammarException
- Java jsp 下拉图片框是怎么做到的?
- JSP保存页面信息到文件
目前办法是把汉字字符编码再传送,暂时解决了。
encodeURIComponent("汉字")
例如:
String url = "http://localhost:90/test/login.do?id=" + onlineMd.getId() + "&org=" + java.net.URLEncoder.encode(onlineMd.getOrg(), "utf-8");
后台接受数据的地方使用编码转换:例如
String username=new String(username.getBytes("ISO8859-1"),"UTF-8");
String org = new String(request.getParameter("org").getBytes("ISO-8859-1"),"UTF-8");
http://topic.csdn.net/u/20100604/16/23bfbdbb-94e3-473a-952b-22967a01a0f8.html
#35楼 得分:0回复于:2010-06-04 22:46:41用这个方法做下转换试试看(DB:ORACLE)。package aa.bb.cc;
import java.io.*;public class TransFormat {
// 插入数据库之前使用此方法进行转换
public static String GBToUnicode(String strIn)
{
byte[] b;
String strOut = null;
if(strIn == null || (strIn.trim()).equals(""))
return strIn;
try
{
b = strIn.getBytes("GBK");
strOut = new String(b,"ISO8859_1");
}
catch(UnsupportedEncodingException e)
{
}
return strOut;
} // 从数据库取数据库后使用此方法进行转换
public static String UnicodeToGB(String strIn)
{
String strOut = null;
int strLen = 0;
strOut = ""; if(strIn == null || (strIn.trim()).equals(""))
return strIn;
try
{
byte[] b = strIn.getBytes("ISO8859_1");
strOut = new String(b,"GBK"); // 处理存在半个汉字的情况
strLen = strOut.length();
if(strLen == 0)
{
String tempStr = null;
strLen = b.length;
tempStr = strIn.substring(0,strLen - 1);
byte[] b1 = tempStr.getBytes("ISO8859_1");
strOut = new String(b1,"GBK");
b1 = null;
}
b = null;
}
catch(Exception e)
{
}
return strOut;
} // 一般情况下不调用该方法
// 两种字符集的转换
public static String ChangeUnicode(String strIn,
String SourceCode,String TargetCode)
{
String strOut = null;
if(strIn == null || (strIn.trim()).equals(""))
return strIn;
try
{
byte[] b = strIn.getBytes(SourceCode);
strOut = new String(b,TargetCode);
}
catch(Exception e)
{
}
return strOut;
}}
=====
a.jsp<%
out.println(UnicodeToGB(request.getparameter(menthod)));
%>
JavaScript: encodeURI() 函数使用 URI 编码的话就不会再产生这种问题了。