jsp包含html乱码
jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html >
<head>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body>
显示<%@include file="index_test.htm"%>
</body>
</html>
index_test.htm
欢迎
------解决方案--------------------
JSP文件调用HTML文件时,中文内容出现乱码的解决
JSP文件:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<html>
<head>
<title>JSP Include指令的使用</title>
</head>
<body>
<%@include file="1.html"%>
<%out.println("<h2>这是JSP网页中的文字</h2>");%>
<%@include file="1.html"%>
</body>
</html>
===================================================================================================================================
HTML文件(1.html)
<!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>
<p>这是HTML的内容</p>
</body>
</html>
===================================================================================================================================
问题:运行JSP文件时,“这是HTML的内容”中的中文部分出现了乱码
解决:将<%@page pageEncoding="UTF-8"%>回到HTML文件<head>在之上就能解决
原理:pageEncoding默认情况下的值是”IS0-8859-1“
- - 网上找的