浅谈SpringMVC过滤器CharacterEncodingFilter和HiddenHttpMethodFilter
1、解决乱码CharacterEncodingFilter
在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>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
采用HiddentHttpMethodFilter过滤器的方式实现put、delete
第一步:web.xml
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
第二步:jsp
<h1>HiddenHttpMethodFilter过滤器</h1>
<form action="params/testHttpMethodFilter" method="post">
用户名称:<input type="test" name="username"/>
<input type="hidden" name="_method" value="PUT"/>
<input type="submit"/>
</form>
第三步:controller
@RequestMapping(value="/testHttpMethodFilter",method = RequestMethod.PUT)
@ResponseBody
public String testHttpMethodFilter(){
System.out.println("testHttpMethodFilter.put");
return "success7676766767";
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/87261.html