jsp里使用alert中文乱码解决方法

我用的是Maven的webapp模板创建的web项目,在他自动生成的index.jsp里使用alert()时,中文乱码。

解决方式:删掉index.jsp,重新new一个。

我发现Maven自动生成的jsp和使用IDEA 重新new的jsp不一样,新new的多了一个

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2022/12/10
  Time: 19:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <script>
        alert("欢迎来到夜之城");
    </script>
</body>
</html>

补充:如果上面不行,可能还需要下面

Settings---》Editor---》File Encoding,如下:全都设成UTF-8.然后把原来的 黄色target文件删掉,重新运行。

猜你喜欢

转载自blog.csdn.net/weixin_60664694/article/details/128268203