1

sitemeshを使用しているspring-mvcアプリケーションがあります。私が抱えている問題は、私のページはUTF-8である必要がありますが、sitemeshはISO-8859-1文字セットをサポートしているということです。UTF-8ページで動作するようにSitemeshを構成することは可能ですか?私はページの正確さを表示しようとしている簡単な例を使用していますが、代わりになどのような無効な文字を取得しています

私が使用しているファイルは次のとおりです。

sitemesh.xml

<sitemesh>
    <property name="decorators-file" value="/WEB-INF/decorators.xml" />
    <excludes file="${decorators-file}" />

    <page-parsers>
        <parser content-type="text/html"
            class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
        <parser content-type="text/html;charset=ISO-8859-1"
            class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
    </page-parsers>

    <decorator-mappers>
        <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
            <param name="config" value="${decorators-file}" />
        </mapper>
    </decorator-mappers>
</sitemesh>

web.xml

...
<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
...

decorators.xml

<decorators defaultdir="/decorators">
    <decorator name="main" page="main.jsp">
          <pattern>/*</pattern>
    </decorator>
</decorators>

main.jsp

<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<html>
<body>
 some stuff here
...
<div class="main"><decorator:body /></div>
</body>
</html>

私のサンプルページ:

<html>
...
<body>
     mùpeeàçè
</body>
</html>

誰か考えがありますか?ありがとう

4

3 に答える 3

3

あなたはweb.xmlでそれを試すことができます(forceEncodingが重要です、それは私にとってはうまくいきます)

    <filter>
    <filter-name>SetCharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>SetCharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
于 2013-04-11T13:26:42.217 に答える
1

CharacterEncodingFilter を web.xml に追加しようとしましたか? 参照: http://ibnaziz.wordpress.com/2008/06/10/spring-utf-8-conversion-using-characterencodingfilter/

于 2011-06-03T01:21:17.907 に答える
0

返信はちょっと遅いですが、私が何時間も無駄にしたことから誰かが恩恵を受けることを願っています. Spring のフィルターも機能しませんでした。私は自分で書き、servletResponse の contentType を手動で設定しました。今のところ問題はありません。

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws ServletException, IOException {
    resp.setContentType("text/html; charset=UTF-8");
    chain.doFilter(req, resp);
}


<filter>
    <filter-name>EncodingFilter</filter-name>
    <filter-class>com.muratdozen.mvc.filters.EncodingFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>EncodingFilter</filter-name>
    <url-pattern>/ui/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
    <filter-name>EncodingFilter</filter-name>
    <url-pattern>/WEB-INF/views/*</url-pattern>
    <dispatcher>ERROR</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>
于 2013-11-17T18:54:58.230 に答える