在JSP页面中引用HTML页面出现乱码,应该怎么解决呢?我能想到的方法都用尽了,还是不行!
这是我的一个HTML页面的源代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>多选测试</title>
</head>
<body>
<form action="test.jsp">
爱好:<input type="checkbox" name="interest" value="登山"/>登山
<input type="checkbox" name="interest" value="游泳"/>游泳
<input type="checkbox" name="interest" value="篮球"/>篮球
<input type="checkbox" name="interest" value="足球"/>足球
<br/>
<input type="submit" value="提交"/>
</form>
</body>
</html>
<%@ page language="java" pageEncoding="gb2312"%>JSP 乱码
<html>
<head>
<title>多选结果测试</title>
</head>
<body>
<%
request.setCharacterEncoding("gb2312");
String[] interest=request.getParameterValues("interest");
for(int i=0;i<interest.length;i++)
{
out.println("您的爱好有:"+interest[i]+",");
}
%>
</body>
</html>
</body>
</html>
<%@page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<title>多选结果测试</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String[] interest = request.getParameterValues("interest");
for (int i = 0; i < interest.length; i++) {
out.println("您的爱好有:" + interest[i] + ",");
}
%>
</body>
</html>
[解决办法]
html 加 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
jsp 加
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>