乱码及restful
1.乱码的解决--通过过滤器来解决乱码:springmvc中提供CharacterEncodingFilter解决post乱码
<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>*.do</url-pattern> </filter-mapping>
如果是get方式乱码:1.修改tomcat的配置解决 2.自定义乱码解决的过滤器
2.restful风格的url
优点:轻量级,安全,效率高
//http://localhost:8888/springmvc_data/1/123/delete.do @RequestMapping("/{id}/{uid}/delete") public String hello(@PathVariable int uid,@PathVariable int id){ System.out.println("id:"+id); System.out.println("uid:"+uid); return "/index.jsp"; }
3.同一个controller通过参数来到达不同的处理方法--不重要