jsp外部引入js文件出现中文乱码
1.设置项目编码为utf-8
2.删除相关文件并重新创建编码为utf-8的同名文件
3.设置jsp头、html的meta、引用的js链接为utf-8
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="${pageContext.request.contextPath }/js/pwdmodify.js" charset="UTF-8" ></script>
4.过滤器设置请求内容编码和响应内容编码
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
5.设置tomcat配置文件server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
6.设置web.xml
<web-app>
...
<jsp-config>
<jsp-property-group>
<display-name>HtmlConfiguration</display-name>
<url-pattern>*.html</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
<jsp-property-group>
<display-name>JspConfiguration</display-name>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
<jsp-property-group>
<display-name>JsConfiguration</display-name>
<url-pattern>*.js</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
...
</web-app>
版权声明:本文为hellomingsheng原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。