spring mvc环境通过 过滤器设置请求响应字符编码
1. web.xml配置过滤器进行字符编码设置
<filter> <filter-name>characterEncodingFilter</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> <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.pom.xml配置有关 maven 编译时静态文件的处理
pom.xml文件
<build> <finalName>spring-mvc01</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> ...... </plugins> </pluginManagement> <!--静态资源导出问题--> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build>
3.测试一下表单提交
- index01.html 建立一个表单
<form action="./index/index01" method="get" > <input type="text" name="name" /> <input type="submit" value="submit" /> </form>
- 控制器获取
@RequestMapping("index01") public String index01(@RequestParam("name") String name) { System.out.println(name); return "index01"; }
标签:xml,index01,name,spring,maven,mvc,过滤器 From: https://www.cnblogs.com/fps2tao/p/16932880.html