response.setContentType("gb2312");
或者
String test=new String(request.getParameter("test").getBytes("ISO-8859-1"),"gb2312");
或者
String test=new String(request.getParameter("test").getBytes("ISO-8859-1"),"gb2312");
解决方案 »
- 菜鸟问题:启动tomcat报错
- textarea水平滚动条问题
- GBK UTF-8 decode 和 encode 互转
- 奇怪的乱码问题,
- javascript中的这个方法isNaN是不是判断是数字的?
- The method prevous() is undefined for the type ResultSet 错误信息
- !!!!!!!!!!100分求解(struts下拉列表初始化数据)!!!!!!!!!!
- 关于web应用(jsp)性能的探讨
- 这个方法该如何实现
- jsp和servlet的传递问题
- JSP 测试 Mysql 连接NoClassDefFoundError
- 哪位仁兄在Web上做过类似PowerPoint的东东?
httpServletRequest.setCharacterEncoding("GBK");
或String test=new String(request.getParameter("test").getBytes("ISO8859_1"), "GBK");
我把所有的代码贴上
<%@ page language="java" import="java.util.*,java.net.*" pageEncoding="GB2312" contentType="text/html; charset=gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'sender.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
response.setContentType("gb2312");
String url = "receiver.jsp?test=谭老师";
response.sendRedirect(response.encodeRedirectURL(url));
%> </body>
</html>
ISO8859_1要看环境是不是这个字符集
web.xml是这样的<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app> <welcome-file-list>
<welcome-file>search.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>weblogic.httpd.inputCharset./*</param-name>
<param-value>GB2312</param-value>
</context-param>
</web-app>
可以获得当前环境的字符集
就可以解决中文显示问题了。
不过最好还是做个刷新功能。
那么,"receiver.jsp?test=" + GBK_URLEncode("谭老师")public static String GBK_URLEncode( String str ) throws UnsupportedEncodingException
{
StringBuffer buf = new StringBuffer();
byte [] b = str.getBytes("GBK"); for(int i=0; i<b.length; i++)
{
if( b[i] > 32 && b[i] < 128 )
buf.append( b[i] );
else
{
buf.append( "%" );
buf.append( Integer.toHexString((int)0x200 + b[i]).substring(1) );
}
} return buf.toString();
}
String s = URLEncoder.encode("中文", "utf-8");
System.out.println(s);