解决乱码
通过过滤器解决乱码
spring mvc提供了
CharacterEncodingFilter
来解决乱码问题- 只能解决post的乱码问题
<filter> <filter-name>encoding</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>encoding</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping>
- 只能解决post的乱码问题
get方式乱码
- 修改tomcat配置
- 自定义乱码过滤器
Restful风格的url
- 优点: 轻量级,安全,效率高
@RequestMapping("/delete/{id}/{uid}") public String delete(@PathVariable int id, @PathVariable int uid) { System.out.println(id + " --- " + uid); return "/index.jsp"; }
- 优点: 轻量级,安全,效率高
通过同一个Controller选择不同处理方法,一般不会使用
@Controller @RequestMapping("/hello2") public class Hello2Controller { @RequestMapping(params="method=add", method=RequestMethod.GET) public String add() { System.out.println("add"); return "redirect:/index.jsp"; } public String update() { System.out.println("update"); return "redirect:/index.jsp"; } public String delete() { System.out.println("delete"); return "redirect:/index.jsp"; } }
- url中需要添加
?method=add
- url中需要添加