【发布时间】:2018-12-02 09:15:44
【问题描述】:
当我使用 RequsetDispatcher 运行 JSP 页面时,它会向我显示带有“????...”的西里尔文内容。
RequestDispatcher view = request.getRequestDispatcher("/view.jsp");
这是我尝试过的:
我正在使用 Apache Tomcat,并在 VM 选项中添加了它:
-Dfile.encoding=UTF-8
在jsp文件的开头:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
在 web.xml 中:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>utf-8</page-encoding>
</jsp-property-group>
</jsp-config>
<filter>
<filter-name>CharSet</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharSet</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
在tomcat配置文件conf/server.xml的connectors中:
URIEncoding="UTF-8"
它仍然不起作用。任何想法如何解决它?
编辑:当我在 Servlet 方法中添加 response.setCharacterEncoding("UTF-8"); 时已修复。
【问题讨论】:
-
你用的是什么应用服务器?