Eclipse中新建jsp文件访问页面时乱码问题

新建.jsp文件,charset和pageEncoding默认是ISO-8859-1,这样的话访问页面时会出现乱码,解决办法:将charset和pageEncoding改为UTF-8(或者GBK/GB2312/GB18030,如果想具体了解几种编码的前世今生可参考另一篇文章:网页编码就是那点事).

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

</body>
</html>
View Code

修改后的代码如下:

<%@ 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>
    <script type="text/javascript">alert("中文!");</script>
    中文!
</body>
</html>
View Code

 

总结:修改编码格式为UTF-8

posted @ 2016-06-10 22:21  习惯沉淀  阅读(1088)  评论(0编辑  收藏  举报