【问题标题】:JSP doesn't display cyrillic content?JSP 不显示西里尔文内容?
【发布时间】: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"); 时已修复。

【问题讨论】:

  • 你用的是什么应用服务器?

标签: java jsp tomcat servlets


【解决方案1】:

看来您的问题很可能与您使用的应用服务器有关。

请参考此线程并尝试通过将应用程序服务器配置文件更改为使用 UTF-8 来解决您的问题 -> How to get UTF-8 working in Java webapps

【讨论】:

    【解决方案2】:

    缺少的部分是在 Servlet 的 dopost 方法的开头添加 response.setCharacterEncoding("UTF-8");

    【讨论】:

      猜你喜欢
      • 2014-08-22
      • 1970-01-01
      • 2016-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-13
      相关资源
      最近更新 更多