标签:har list method 后缀 address patch scan load size
简单Helloworld
jar包使用spring的就可以了
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:aop="http://www.springframework.org/schema/aop" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" 6 xmlns:context="http://www.springframework.org/schema/context" 7 xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 8 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 9 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd 10 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd"> 11 12 <context:component-scan base-package="com.tzy.springmvc"></context:component-scan> 13 14 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 15 <property name="prefix" value="/WEB-INF/views/"></property> 16 <property name="suffix" value=".jsp"></property> 17 </bean> 18 </beans>
1 package com.tzy.springmvc.handlers; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.RequestMapping; 5 6 @Controller 7 public class HelloWorld { 8 /** 9 * 使用@RequestMapping注解来映射请求的URL 10 * 返回值会通过视图解析器解析为实际的物理视图,对于InternalResourceViewResolver视图解析器,会做如下的解析: 11 * 通过prefix(前缀)+returnVal+suffix(后缀) 这样的方式得到实际的物理视图,然后会转发操作 12 * /WEB-INF/views/success.jsp 13 * @return 14 */ 15 @RequestMapping("/helloworld") 16 public String hello() { 17 System.out.println("hello world"); 18 return "success"; 19 } 20 }
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 3 <display-name>springmvc</display-name> 4 <welcome-file-list> 5 <welcome-file>index.html</welcome-file> 6 <welcome-file>index.htm</welcome-file> 7 <welcome-file>index.jsp</welcome-file> 8 <welcome-file>default.html</welcome-file> 9 <welcome-file>default.htm</welcome-file> 10 <welcome-file>default.jsp</welcome-file> 11 </welcome-file-list> 12 <!-- The front controller of this Spring Web application, responsible for handling all application requests --> 13 <servlet> 14 <servlet-name>springDispatcherServlet</servlet-name> 15 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 16 <!-- 配置despatcherServlet的一个初始化参数:配置springMVC的配置文件的位置和名称 --> 17 <init-param> 18 <param-name>contextConfigLocation</param-name> 19 <param-value>classpath:springmvc.xml</param-value> 20 </init-param> 21 <load-on-startup>1</load-on-startup> 22 </servlet> 23 24 <!-- Map all requests to the DispatcherServlet for handling --> 25 <servlet-mapping> 26 <servlet-name>springDispatcherServlet</servlet-name> 27 <url-pattern>/</url-pattern> 28 </servlet-mapping> 29 30 </web-app>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <a href="helloworld">Hello World</a> 11 </body> 12 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <h4>Success Page</h4> 11 </body> 12 </html>
Rest风格
/**
* Rest风格的URL
* 以CRUD为例
* 新增:/order POST
* 修改:/order/1 PUT
* 获取:/order/1 GET
* 删除:/order/1 DELETE
*
* 如何发送PUT和DELETE请求呢
* 需要配置HiddenHttpMethodFilter
* 需要发送给POST请求
* 需要在发送POST请求的时 携带一个 name="_method"的隐藏域,值为DELETE或PUT
*
* 在SpringMVC的目标方法中如何得到id呢?
* 使用@PathVariable注解
* @param id
* @return
*/
修改上述代码
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns="http://java.sun.com/xml/ns/javaee" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 5 id="WebApp_ID" version="2.5"> 6 <display-name>springmvc</display-name> 7 <welcome-file-list> 8 <welcome-file>index.html</welcome-file> 9 <welcome-file>index.htm</welcome-file> 10 <welcome-file>index.jsp</welcome-file> 11 <welcome-file>default.html</welcome-file> 12 <welcome-file>default.htm</welcome-file> 13 <welcome-file>default.jsp</welcome-file> 14 </welcome-file-list> 15 <!-- The front controller of this Spring Web application, responsible for 16 handling all application requests --> 17 <servlet> 18 <servlet-name>springDispatcherServlet</servlet-name> 19 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 20 <!-- 配置despatcherServlet的一个初始化参数:配置springMVC的配置文件的位置和名称 --> 21 <init-param> 22 <param-name>contextConfigLocation</param-name> 23 <param-value>classpath:springmvc.xml</param-value> 24 </init-param> 25 <load-on-startup>1</load-on-startup> 26 </servlet> 27 28 <!-- Map all requests to the DispatcherServlet for handling --> 29 <servlet-mapping> 30 <servlet-name>springDispatcherServlet</servlet-name> 31 <url-pattern>/</url-pattern> 32 </servlet-mapping> 33 34 <!-- 配置hiddenHttpMethodFilter可以把post请求转成DELETE或PUT请求 --> 35 <filter> 36 <filter-name>HiddenHttpMethodFilter</filter-name> 37 <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> 38 </filter> 39 <filter-mapping> 40 <filter-name>HiddenHttpMethodFilter</filter-name> 41 <url-pattern>/*</url-pattern> 42 </filter-mapping> 43 </web-app>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <a href="helloworld">Hello World</a> 11 <a href="testPathVariable/1">Test PathVariable</a> 12 <br /> 13 <br /> 14 <a href="testRest/1">Test Rest Get</a> 15 <br /> 16 <br /> 17 <form action="testRest" method="post"> 18 <input type="submit" value="TestRest POST" /> 19 </form> 20 <br /> 21 <br /> 22 <form action="testRest/1" method="post"> 23 <input type="hidden" name="_method" value="DELETE" /> <input 24 type="submit" value="TestRest DELETE" /> 25 </form> 26 <br /> 27 <br /> 28 <form action="testRest/1" method="post"> 29 <input type="hidden" name="_method" value="PUT" /> <input 30 type="submit" value="TestRest PUT" /> 31 </form> 32 </body> 33 </html>
1 package com.tzy.springmvc.handlers; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.PathVariable; 5 import org.springframework.web.bind.annotation.RequestMapping; 6 import org.springframework.web.bind.annotation.RequestMethod; 7 8 @Controller 9 public class HelloWorld { 10 /** 11 * 使用@RequestMapping注解来映射请求的URL 12 * 返回值会通过视图解析器解析为实际的物理视图,对于InternalResourceViewResolver视图解析器,会做如下的解析: 13 * 通过prefix(前缀)+returnVal+suffix(后缀) 这样的方式得到实际的物理视图,然后会转发操作 14 * /WEB-INF/views/success.jsp 15 * @return 16 */ 17 @RequestMapping("/helloworld") 18 public String hello() { 19 System.out.println("hello world"); 20 return "success"; 21 } 22 23 /** 24 * @PathVariable可以来映射URL中的占位符到目标方法的参数中 25 * @param id 26 * @return 27 */ 28 @RequestMapping("/testPathVariable/{id}") 29 public String testPathVariable(@PathVariable("id") Integer id){ 30 System.out.println("testPathVariable"+id); 31 return "success"; 32 } 33 /** 34 * Rest风格的URL 35 * 以CRUD为例 36 * 新增:/order POST 37 * 修改:/order/1 PUT 38 * 获取:/order/1 GET 39 * 删除:/order/1 DELETE 40 * 41 * 如何发送PUT和DELETE请求呢 42 * 需要配置HiddenHttpMethodFilter 43 * 需要发送给POST请求 44 * 需要在发送POST请求的时 携带一个 name="_method"的隐藏域,值为DELETE或PUT 45 * 46 * 在SpringMVC的目标方法中如何得到id呢? 47 * 使用@PathVariable注解 48 * @param id 49 * @return 50 */ 51 @RequestMapping(value="/testRest/{id}",method=RequestMethod.GET) 52 public String testRest(@PathVariable("id") Integer id){ 53 System.out.println("testRest GET"+id); 54 return "success"; 55 } 56 @RequestMapping(value="/testRest",method=RequestMethod.POST) 57 public String testRest(){ 58 System.out.println("testRest POST"); 59 return "success"; 60 } 61 @RequestMapping(value="/testRest/{id}",method=RequestMethod.DELETE) 62 public String testRestDELETE(@PathVariable("id") Integer id){ 63 System.out.println("testRest DELETE"+id); 64 return "success"; 65 } 66 @RequestMapping(value="/testRest/{id}",method=RequestMethod.PUT) 67 public String testRestPUT(@PathVariable("id") Integer id){ 68 System.out.println("testRest PUT"+id); 69 return "success"; 70 } 71 72 }
相应的可以使用@RequestParam注解获取请求参数方法和上面的@PathVariable注解基本一样
属性值
value="age" 值即请求参数的参数名
required=false 该参数值是否必须,默认值true
defaultValue 请求参数的默认值(如需要 int型就需要加入这个,不然null复不上)
@RequestHeader注解,映射请求头,用法同上
@CookieValue注解,映射Cookie值,用法同上
使用POJO对象绑定请求参数
1 package com.tzy.springmvc.entities; 2 3 public class User { 4 private String username; 5 private String password; 6 private String email; 7 private Integer age; 8 private Address address; 9 public String getUsername() { 10 return username; 11 } 12 public void setUsername(String username) { 13 this.username = username; 14 } 15 public String getPassword() { 16 return password; 17 } 18 public void setPassword(String password) { 19 this.password = password; 20 } 21 public String getEmail() { 22 return email; 23 } 24 public void setEmail(String email) { 25 this.email = email; 26 } 27 public Integer getAge() { 28 return age; 29 } 30 public void setAge(Integer age) { 31 this.age = age; 32 } 33 public Address getAddress() { 34 return address; 35 } 36 public void setAddress(Address address) { 37 this.address = address; 38 } 39 @Override 40 public String toString() { 41 return "User [username=" + username + ", password=" + password + ", email=" + email + ", age=" + age + ", address=" 42 + address + "]"; 43 } 44 45 }
1 package com.tzy.springmvc.entities; 2 3 public class Address { 4 private String province; 5 private String city; 6 7 public String getProvince() { 8 return province; 9 } 10 11 public void setProvince(String province) { 12 this.province = province; 13 } 14 15 public String getCity() { 16 return city; 17 } 18 19 public void setCity(String city) { 20 this.city = city; 21 } 22 23 @Override 24 public String toString() { 25 return "Address [province=" + province + ", city=" + city + "]"; 26 } 27 28 }
这样就可以获取一个POJO了
处理模型数据
SpringMVC提供了以下几种途径输出模型数据:
ModelAndView:处理方法返回值类型为ModelAndView时,方法体即可通过该对象添加模型数据
Map及Model:入参为org.springframework.ui.Model org.springframwork.ui.ModelMap或java.util.Map时,处理方法返回时,Map中的数据会自动添加到模型中。
@sessionAttributes:将模型中的某个属性暂存到HttpSession中,以便多个请求之间可以共享这个属性
-若希望在多个请求之间公用某个模型属性数据,则可以在控制器上标注一个@SessionAttributes,SpringMVC将在模型中对应的属性暂存到HttpSession中
@MoodelAttribute:方法入参标注注解后,入参的对象就会放到数据模型中
-由@ModelAttribute标记的方法,会在每个目标方法执行之前被SpringMVC调用
1 package com.tzy.springmvc.entities; 2 3 public class User { 4 private int id; 5 6 private String username; 7 private String password; 8 private String email; 9 private Integer age; 10 private Address address; 11 12 public String getUsername() { 13 return username; 14 } 15 16 public void setUsername(String username) { 17 this.username = username; 18 } 19 20 public String getPassword() { 21 return password; 22 } 23 24 public void setPassword(String password) { 25 this.password = password; 26 } 27 28 public String getEmail() { 29 return email; 30 } 31 32 public void setEmail(String email) { 33 this.email = email; 34 } 35 36 public Integer getAge() { 37 return age; 38 } 39 40 public void setAge(Integer age) { 41 this.age = age; 42 } 43 44 public Address getAddress() { 45 return address; 46 } 47 48 public void setAddress(Address address) { 49 this.address = address; 50 } 51 52 53 54 public int getId() { 55 return id; 56 } 57 58 public void setId(int id) { 59 this.id = id; 60 } 61 62 public User(String username, String password, String email, Integer age) { 63 super(); 64 this.username = username; 65 this.password = password; 66 this.email = email; 67 this.age = age; 68 } 69 70 public User(int id, String username, String password, String email, Integer age) { 71 super(); 72 this.id = id; 73 this.username = username; 74 this.password = password; 75 this.email = email; 76 this.age = age; 77 } 78 79 public User() { 80 super(); 81 } 82 83 @Override 84 public String toString() { 85 return "User [id=" + id + ", username=" + username + ", password=" + password + ", email=" + email + ", age=" 86 + age + ", address=" + address + "]"; 87 } 88 89 90 91 }
1 package com.tzy.springmvc.entities; 2 3 public class Address { 4 private String province; 5 private String city; 6 7 public String getProvince() { 8 return province; 9 } 10 11 public void setProvince(String province) { 12 this.province = province; 13 } 14 15 public String getCity() { 16 return city; 17 } 18 19 public void setCity(String city) { 20 this.city = city; 21 } 22 23 @Override 24 public String toString() { 25 return "Address [province=" + province + ", city=" + city + "]"; 26 } 27 28 }
1 package com.tzy.springmvc.handlers; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.PathVariable; 5 import org.springframework.web.bind.annotation.RequestMapping; 6 import org.springframework.web.bind.annotation.RequestMethod; 7 8 @Controller 9 public class HelloWorld { 10 /** 11 * 使用@RequestMapping注解来映射请求的URL 12 * 返回值会通过视图解析器解析为实际的物理视图,对于InternalResourceViewResolver视图解析器,会做如下的解析: 13 * 通过prefix(前缀)+returnVal+suffix(后缀) 这样的方式得到实际的物理视图,然后会转发操作 14 * /WEB-INF/views/success.jsp 15 * @return 16 */ 17 @RequestMapping("/helloworld") 18 public String hello() { 19 System.out.println("hello world"); 20 return "success"; 21 } 22 23 /** 24 * @PathVariable可以来映射URL中的占位符到目标方法的参数中 25 * @param id 26 * @return 27 */ 28 @RequestMapping("/testPathVariable/{id}") 29 public String testPathVariable(@PathVariable("id") Integer id){ 30 System.out.println("testPathVariable"+id); 31 return "success"; 32 } 33 /** 34 * Rest风格的URL 35 * 以CRUD为例 36 * 新增:/order POST 37 * 修改:/order/1 PUT 38 * 获取:/order/1 GET 39 * 删除:/order/1 DELETE 40 * 41 * 如何发送PUT和DELETE请求呢 42 * 需要配置HiddenHttpMethodFilter 43 * 需要发送给POST请求 44 * 需要在发送POST请求的时 携带一个 name="_method"的隐藏域,值为DELETE或PUT 45 * 46 * 在SpringMVC的目标方法中如何得到id呢? 47 * 使用@PathVariable注解 48 * @param id 49 * @return 50 */ 51 @RequestMapping(value="/testRest/{id}",method=RequestMethod.GET) 52 public String testRest(@PathVariable("id") Integer id){ 53 System.out.println("testRest GET"+id); 54 return "success"; 55 } 56 @RequestMapping(value="/testRest",method=RequestMethod.POST) 57 public String testRest(){ 58 System.out.println("testRest POST"); 59 return "success"; 60 } 61 @RequestMapping(value="/testRest/{id}",method=RequestMethod.DELETE) 62 public String testRestDELETE(@PathVariable("id") Integer id){ 63 System.out.println("testRest DELETE"+id); 64 return "success"; 65 } 66 @RequestMapping(value="/testRest/{id}",method=RequestMethod.PUT) 67 public String testRestPUT(@PathVariable("id") Integer id){ 68 System.out.println("testRest PUT"+id); 69 return "success"; 70 } 71 72 }
1 package com.tzy.springmvc.handlers; 2 3 import java.util.Arrays; 4 import java.util.Date; 5 import java.util.Map; 6 7 import org.springframework.stereotype.Controller; 8 import org.springframework.web.bind.annotation.ModelAttribute; 9 import org.springframework.web.bind.annotation.RequestMapping; 10 import org.springframework.web.bind.annotation.RequestParam; 11 import org.springframework.web.bind.annotation.SessionAttributes; 12 import org.springframework.web.servlet.ModelAndView; 13 14 import com.tzy.springmvc.entities.User; 15 /** 16 * @SessionAttributes除了可以通过属性名指定需要放到会话中的属性外(实际上使用value属性值) 17 * 还可以通过模型属性对对象类型制定哪些模型属性需要放到会话中(实际使用的是types属性值) 18 * 注意该注解只能放在类上面,而不能修饰方法 19 * @author tzy 20 * 21 */ 22 //@SessionAttributes({"user"}) 23 //@SessionAttributes(value={"user"}) 24 @SessionAttributes(types={User.class}) 25 @Controller 26 public class Testmvc { 27 @RequestMapping("/testPOJO") 28 public String testPojo(User user) { 29 System.out.println("testPOJO: "+user); 30 return "success"; 31 } 32 //目标方法的返回值可以是ModelAndView类型 33 //其中可以包含视图和模型信息 34 //springMVC会把ModelAndView的model中数据放入到request域对象中 35 @RequestMapping("/testModelAndView") 36 public ModelAndView testModelAndView() { 37 String viewName = "success";//视图的名字 38 ModelAndView modelAndView = new ModelAndView(viewName); 39 //添加模型数据到ModelAndView中 40 modelAndView.addObject("time",new Date()); 41 42 return modelAndView; 43 } 44 /** 45 * 目标方法可以添加Map类型(实际上可以是Model类型或ModelMap类型) 46 * @param map 47 * @return 48 */ 49 @RequestMapping("/testMap") 50 public String testMap(Map<String,Object> map) { 51 map.put("names", Arrays.asList("Tom","Jerry","Mike")); 52 53 return "success"; 54 } 55 @RequestMapping("/testSessionAttributes") 56 public String testSessionAttributes(Map<String,Object> map){ 57 User u = new User("aa", "asd", "zzz", 123); 58 map.put("user", u); 59 return "success"; 60 } 61 62 63 64 /** 65 * 由@ModelAttribute标记的方法,会在每个目标方法执行之前被SpringMVC调用 66 * @param id 67 * @param map 68 */ 69 @ModelAttribute 70 public void getUser(@RequestParam(value="id",required=false) Integer id,Map<String,Object> map){ 71 if(id!=null){ 72 User u = new User(1, "Tom", "123", "Tom@qq.com", 12); 73 System.out.println("从数据库中获取对象为"+u); 74 map.put("user", u); 75 } 76 } 77 @RequestMapping("/testModelAttribute") 78 public String testModelAttribute(User u){ 79 System.out.println("修改: "+u); 80 return "success"; 81 } 82 }
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:aop="http://www.springframework.org/schema/aop" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" 6 xmlns:context="http://www.springframework.org/schema/context" 7 xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 8 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 9 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd 10 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd"> 11 12 <context:component-scan base-package="com.tzy.springmvc"></context:component-scan> 13 14 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 15 <property name="prefix" value="/WEB-INF/views/"></property> 16 <property name="suffix" value=".jsp"></property> 17 </bean> 18 </beans>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns="http://java.sun.com/xml/ns/javaee" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 5 id="WebApp_ID" version="2.5"> 6 <display-name>springmvc</display-name> 7 <welcome-file-list> 8 <welcome-file>index.html</welcome-file> 9 <welcome-file>index.htm</welcome-file> 10 <welcome-file>index.jsp</welcome-file> 11 <welcome-file>default.html</welcome-file> 12 <welcome-file>default.htm</welcome-file> 13 <welcome-file>default.jsp</welcome-file> 14 </welcome-file-list> 15 <!-- The front controller of this Spring Web application, responsible for 16 handling all application requests --> 17 <servlet> 18 <servlet-name>springDispatcherServlet</servlet-name> 19 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 20 <!-- 配置despatcherServlet的一个初始化参数:配置springMVC的配置文件的位置和名称 --> 21 <init-param> 22 <param-name>contextConfigLocation</param-name> 23 <param-value>classpath:springmvc.xml</param-value> 24 </init-param> 25 <load-on-startup>1</load-on-startup> 26 </servlet> 27 28 <!-- Map all requests to the DispatcherServlet for handling --> 29 <servlet-mapping> 30 <servlet-name>springDispatcherServlet</servlet-name> 31 <url-pattern>/</url-pattern> 32 </servlet-mapping> 33 34 <!-- 配置hiddenHttpMethodFilter可以把post请求转成DELETE或PUT请求 --> 35 <filter> 36 <filter-name>HiddenHttpMethodFilter</filter-name> 37 <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> 38 </filter> 39 <filter-mapping> 40 <filter-name>HiddenHttpMethodFilter</filter-name> 41 <url-pattern>/*</url-pattern> 42 </filter-mapping> 43 </web-app>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <a href="helloworld">Hello World</a> 11 <a href="testPathVariable/1">Test PathVariable</a> 12 <br /> 13 <br /> 14 <a href="testRest/1">Test Rest Get</a> 15 <br /> 16 <br /> 17 <form action="testRest" method="post"> 18 <input type="submit" value="TestRest POST" /> 19 </form> 20 <br /> 21 <br /> 22 <form action="testRest/1" method="post"> 23 <input type="hidden" name="_method" value="DELETE" /> <input 24 type="submit" value="TestRest DELETE" /> 25 </form> 26 <br /> 27 <br /> 28 <form action="testRest/1" method="post"> 29 <input type="hidden" name="_method" value="PUT" /> <input 30 type="submit" value="TestRest PUT" /> 31 </form> 32 <br /> 33 <br /> 34 <form action="testPOJO" method="post"> 35 username:<input type="text" name="username" /> 36 <br/> 37 password:<input type="text" name="password" /> 38 <br/> 39 email:<input type="text" name="email" /> 40 <br/> 41 age:<input type="text" name="age" /> 42 <br/> 43 province:<input type="text" name="address.province" /> 44 <br/> 45 city:<input type="text" name="address.city" /> 46 <br/> 47 <input type="submit" value="TestPOJO" /> 48 </form> 49 <br /> 50 <br /> 51 <a href="testModelAndView">TestModelAndView</a> 52 <br /> 53 <br /> 54 <a href="testMap">testMap</a> 55 <br /> 56 <br /> 57 <a href="testSessionAttributes">testSessionAttributes</a> 58 <br /> 59 <br /> 60 <!-- 模拟修改操作 61 原始数据:1,Tom,123,tom@qq.com,12 62 要求:密码不能被修改,表单回显,模拟操作直接在表单填写对应的属性值 63 --> 64 <form action="testModelAttribute" method="post"> 65 <input type="hidden" name="id" value="1"/> 66 username:<input type="text" name="username" value="Tom"/> 67 <br/> 68 email:<input type="text" name="email" value="Tom@qq.com"/> 69 <br/> 70 age:<input type="text" name="age" value="12"/> 71 <br/> 72 <input type="submit" value="testModelAttribute" /> 73 </form> 74 </body> 75 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <h4>Success Page</h4> 11 12 time: ${requestScope.time} 13 <br/> 14 names: ${requestScope.names} 15 <br/> 16 user: ${requestScope.user} 17 <br/> 18 user: ${sessionScope.user} 19 </body> 20 </html>
标签:har list method 后缀 address patch scan load size
原文地址:http://www.cnblogs.com/ttzzyy/p/8000516.html