需要在web.xml中配置一个过滤器
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <!--<!–指定实例化的对象到spring中–>--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext*.xml</param-value> </context-param> <!--如何整合过滤器处理中文乱码问题?--> <filter> <filter-name>EncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--项目启动后里面实例化spring容器--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--1 dispatcher前端控制器--> <servlet> <servlet-name>springssm</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!--3 配置handlemaper handleradapter controller viewRosove--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc/applicationContext_mvc.xml</param-value> </init-param> <!--2 项目启动后就实例化servlet--> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springssm</servlet-name> <!--除jsp之外,其余都拦截--> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
parm-name我看有网友写错了,这边是encoding