spring mvc环境过滤器设置utf8字符编码和maven编译等设置(二)
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"; }
下几篇介绍下:spring mvc 控制器的各种获取参数的方式,其中如果用原生的 HttpServletRequest 获取参数时需要加入ServletAPI 依赖,如:
<!-- ServletAPI --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>