• SpringMVC配置字符过滤器的两种方式


    有时候使用SpringMVC框架提交表单时会出现中文乱码,以下是我亲自试验过的配置字符过滤器的两种:

    1、在web.xml中配置

    <filter>  
    <filter-name>characterEncodingFilter</filter-name>    
    <filter-class>orgspringframeworkwebfilterCharacterEncodingFilter</filter-class>  
    <init-param>   
    <param-name>encoding</param-name>    
    <param-value>UTF-8</param-value>   
    </init-param>   
    <init-param>     
    <param-name>forceEncoding</param-name>    
    <param-value>true</param-value> 
    </init-param>  
    </filter> 
    <filter-mapping>   
    <filter-name>characterEncodingFilter</filter-name>  
    <url-pattern>/*</url-pattern>  
    </filter-mapping>

    2、JavaConfig

    import javax.servlet.Filter;
    
    import org.springframework.web.filter.CharacterEncodingFilter;
    import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
    
    public class JavaSpringIn extends AbstractAnnotationConfigDispatcherServletInitializer {
    
        
         //配置字符过滤器
       @Override  
       protected Filter[] getServletFilters() {  
           CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();  
           characterEncodingFilter.setEncoding("UTF-8");  
           characterEncodingFilter.setForceEncoding(true);  
           return new Filter[] {characterEncodingFilter};  
       }     
    
    }
  • 相关阅读:
    SyntaxError: Non-ASCII character 'xe7' in file解决方法
    python实现微信打飞机游戏
    ubuntu 系统出错一览
    MVC的特点
    架构
    策略模式
    bin
    使用XSLT实现Word下载
    <a>标签的href属性
    call-template和apply-templates
  • 原文地址:https://www.cnblogs.com/lwx521/p/7943565.html
Copyright © 2020-2023  润新知