jsp中的乱码问题,急。。。。 写错应该这样:response.setCharacterEncoding("GBK");但还是不行,是乱码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 tomcat5.0. 的版本 setCharacterEncoding 方法只能对 post 传入的值进行转码。对GET请求的值不能转码。我也不知道为什么。对GET的值,建议用 getBytes()方法进行转。我现在,在tomcat中以不使用setCharacterEncoding 了 index.jsp<html> <head> </head> <body> <form method="POST" name="form1" action="test.jsp" > <input type="input" name="sName" value="这是汉字"> <input type="submit" value="submit"> </form> </body></html>test.jsp<%@ page contentType="text/html;charset=GBK" language="java" %><%@ page import="com.sailing.util.*"%><%//request.setCharacterEncoding("GBK");UtRequest utRequest = new UtRequest(request);String sGbk = utRequest.getString("sName");String sIso = new String(sGbk.getBytes("ISO-8859-1"),"GBK");%>ISO:<%=sGbk%><br>GBK:<%=sIso%><br> UtRequest utRequest 是对转码的一个封装,我同在,所有页面。用我自己封装的request 对于地址中的中文参数转码好象也是不行的,改成下面的就可以了Input.jsp-------------------<%@page contentType="text/html; charset=GBK"%><%! public String ConvertStr(String sStr) { String sRtn = ""; if (sStr == null) { sRtn = ""; } else { try { sRtn = new String(sStr.getBytes("ISO-8859-1"), "GBK"); } catch(Exception ex) { sRtn=""; } } return sRtn; } %><html><script language="javascript"><!--function window_Onload(){ window.focus(); <% //String sTitle1=ConvertStr(request.getParameter("Title1")); String sTitle1=java.net.URLDecoder.decode(request.getParameter("Title1")); %> PromptText.innerText="<%=sTitle1%>";}--></script><body onload="window_Onload()"><P id=PromptText></P></body></html>你那个转码的方法其实根本没用到,因为是没有效果的---------------------servlet------------------------------res.setContentType("text/html;charset=gb2312");String str=java.net.URLEncoder.encode("请输入");res.sendRedirect("Input.jsp?Title1=" + str); java servlet与jsp中文乱码问题 liferay portal 权限的管理 showModalDialog()弹出的模式窗口中的iframe无法编辑 支持邮件和短信的消息通知引擎的设计与实现 tomcat问题,大家进来看一下 求教,调用class文件中的类? 在JSP中能加载的Bean,class名能是变化的吗 双机热备的问题 关于多个servlet Filter过滤器嵌套执行顺序的一个小问题 如何将url中的等号转义 怎样做三十六进制的序列号添加?大家请多帮忙!
对GET的值,建议用 getBytes()方法进行转。我现在,在tomcat中以不使用setCharacterEncoding 了
<html>
<head>
</head>
<body>
<form method="POST" name="form1" action="test.jsp" >
<input type="input" name="sName" value="这是汉字">
<input type="submit" value="submit">
</form>
</body>
</html>test.jsp<%@ page contentType="text/html;charset=GBK" language="java" %>
<%@ page import="com.sailing.util.*"%>
<%
//request.setCharacterEncoding("GBK");
UtRequest utRequest = new UtRequest(request);
String sGbk = utRequest.getString("sName");
String sIso = new String(sGbk.getBytes("ISO-8859-1"),"GBK");
%>ISO:<%=sGbk%><br>
GBK:<%=sIso%><br>
改成下面的就可以了Input.jsp
-------------------
<%@page contentType="text/html; charset=GBK"%>
<%!
public String ConvertStr(String sStr) {
String sRtn = "";
if (sStr == null) {
sRtn = "";
} else {
try
{
sRtn = new String(sStr.getBytes("ISO-8859-1"), "GBK");
}
catch(Exception ex)
{
sRtn="";
}
}
return sRtn;
}
%>
<html>
<script language="javascript">
<!--function window_Onload()
{
window.focus(); <%
//String sTitle1=ConvertStr(request.getParameter("Title1"));
String sTitle1=java.net.URLDecoder.decode(request.getParameter("Title1"));
%>
PromptText.innerText="<%=sTitle1%>";
}
-->
</script>
<body onload="window_Onload()">
<P id=PromptText></P>
</body>
</html>
你那个转码的方法其实根本没用到,因为是没有效果的---------------------
servlet
------------------------------
res.setContentType("text/html;charset=gb2312");
String str=java.net.URLEncoder.encode("请输入");
res.sendRedirect("Input.jsp?Title1=" + str);