-
乱码的解决
通过过滤器解决乱码问题:CharacterEncodingFilter
配置web.xml文件
<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方法提交的数据,可以:
a) 修改tamcat配置
b) 自定义乱码过滤器
-
restful风格,优点:轻量级,安全,效率高
案例一:
@RequestMapping("/hello/{username}")public String hello(@PathVariable("username") String uname,ModelMap mm){System.out.println(uname);mm.addAttribute("msg", uname);return "success";}
效果显示:
案例二:
@Controller@RequestMapping("/hello3/{id}")public class HelloController2 {@RequestMapping(params="method=add",method=RequestMethod.GET)public String add(@PathVariable("id") int id){System.out.println("add");System.out.println(id);return "success";}}
效果显示: