首页上一页 1 下一页尾页 1 条记录 1/1页
JSP中Request对象汉字乱码问题
发表在JavaWeb图书答疑
2012-09-26
是否精华
是
否
版块置顶:
是
否
index.jsp文件内容如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="show.jsp?name=张三&sex=男">解决中文乱码</a>
</body>
</html>
show.jsp文件内容如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
name参数的值为:<%=new String(request.getParameter("name").getBytes("iso-8859-1"),"UTF-8") %><br>
sex参数的值为:<%=new String(request.getParameter("sex").getBytes("iso-8859-1"),"UTF-8") %>
</body>
</html>
浏览器中显示结果:
name参数的值为:张三
sex参数的值为:�
讨教:为什第一个可以成功转为汉字显示,第二个就不行了呢?该怎么改呀?
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="show.jsp?name=张三&sex=男">解决中文乱码</a>
</body>
</html>
show.jsp文件内容如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
name参数的值为:<%=new String(request.getParameter("name").getBytes("iso-8859-1"),"UTF-8") %><br>
sex参数的值为:<%=new String(request.getParameter("sex").getBytes("iso-8859-1"),"UTF-8") %>
</body>
</html>
浏览器中显示结果:
name参数的值为:张三
sex参数的值为:�
讨教:为什第一个可以成功转为汉字显示,第二个就不行了呢?该怎么改呀?