2010-12-17 10 views
1

私はsitemeshを使用しているspring-mvcアプリケーションを持っています。私の問題は、私のページがUTF-8である必要がありますが、sitemeshはISO-8859-1文字セットをサポートしていることです。 UTF-8ページで動作するようにSitemeshを設定することは可能ですか? 私はページcorrecltyを表示しようとしています簡単な例を使用していますが、代わりに私が使用しているファイルがあるなどsitemeshとUTF-8エンコーディング

のように無効な文字を取得しています:

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> 

誰もが任意のアイデアを持っていますか? ありがとう

答えて

3

<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> 
0

返信が遅くちょっとですが、私は他の誰かが、私は上の時間を無駄に何の恩恵を受けるかもしれない願っています(重要forceEncoding、それは私のために動作します)。春のフィルターは私にとってもうまくいきませんでした。私は自分自身を書き、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> 
関連する問題