IDEA加载JSP页面出现中文乱码,如下所示:
JSP页面的内容如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
<link rel="stylesheet" href="css/basic.css">
</head>
<body>
<div>
<h1>用户登录</h1>
<form action="" method="POST">
<img src="img/login.png" ><input type="text" name="username" /><br /><br />
<img src="img/password.png" ><input type="password" name="password" /><br /><br />
<input type="checkbox" name="rememberme" />记住我
<input type="submit" name="login" value="登录" />
</form>
</div>
</body>
</html>
解决方法是在JSP页面中顶部添加
<%@ page pageEncoding="utf-8" %>
JSP改后内容如下:
<%@ page pageEncoding="utf-8" %><%--加载静态JSP页面需设置该页的编码格式为UTF-8--%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
<link rel="stylesheet" href="css/basic.css">
</head>
<body>
<div>
<h1>用户登录</h1>
<form action="" method="POST">
<img src="img/login.png" ><input type="text" name="username" /><br /><br />
<img src="img/password.png" ><input type="password" name="password" /><br /><br />
<input type="checkbox" name="rememberme" />记住我
<input type="submit" name="login" value="登录" />
</form>
</div>
</body>
</html>