Spring velocity 中文亂碼 解決方案


主要有這么幾步,在spring web 的  [sevlet-name]-servlet.xml文件中,修改為:

黑體字體為關鍵,其它根據你的實際情況配置:

 

  <!-- ========================= VIEW DEFINITIONS ========================= -->
     <bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
        <property name="suffix" value=".vm"></property>
        <property name="contentType"><value>text/html;charset=UTF-8</value></property> 
    </bean>
    
    <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath">
            <value>${pgallery.template}</value>
        </property>
        <property name="velocityProperties">
            <props>
                <prop key="input.encoding">utf-8</prop>
                <prop key="output.encoding">utf-8</prop>
            </props>
        </property> 

    </bean>

 

注:

首先要保證開發環境的文件編碼統一,將jsp/html的字符編碼都聲明為utf-8。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM