前端代碼:前端
<form action="${pageContext.request.contextPath }/login.mvc" method="post"> 用戶名:<input name="username" type="text"> 密碼:<input name="password" type="text"> <input type="submit" value="登陸"> </form>
後端代碼:後端
1 @RequestMapping(value="login",method=RequestMethod.POST) 2 public String login(String password,String username){ 3 System.out.println("-登陸-"+username); 4 return "/hello.jsp"; 5 }
前端代碼:數組
<form action="${pageContext.request.contextPath }/arruser.mvc" method="post"> 用戶名1:<input name="username" type="text"> 用戶名2:<input name="username" type="text"> 用戶名3:<input name="username" type="text"> <input type="submit" value="登陸"> </form>
後端代碼(JavaBean的類我就不寫了)cookie
1 @RequestMapping(value="arruser",method=RequestMethod.POST) 2 public String login(String[] username){ 3 System.out.println("-登陸-"+ username[0]); 4 return "/hello.jsp"; 5 }
<form action="${pageContext.request.contextPath }/arruser.mvc" method="post"> 用戶名1:<input name="username" type="text"> 用戶名2:<input name="username" type="text"> 用戶名3:<input name="username" type="text"> <input type="submit" value="登陸"> </form>
後端代碼mvc
1 @RequestMapping(value="arruser",method=RequestMethod.POST) 2 public String login(String[] username){ 3 System.out.println("-登陸-"+ username[0]); 4 return "/hello.jsp"; 5 }
前端代碼app
<form action="${pageContext.request.contextPath }/listuser.mvc" method="post"> 用戶名1:<input name="username" type="text"> 密碼1:<input name="password" type="text"> 用戶名2:<input name="username" type="text"> 密碼2:<input name="password" type="text"> <input type="submit" value="登陸"> </form>
後端代碼jsp
1 public class UsersModel { 2 private List<User> users; 3 public List<User> getUsers() { 4 return users; 5 } 6 public void setUsers(List<User> users) { 7 this.users = users; 8 } 9 }
@RequestMapping(value="listuser",method=RequestMethod.POST) public String login(UsersModel userModel){ System.out.println("用戶1:"+ userModel.getUsers()[0].getUsername()); return "/hello.jsp"; }
① Spring內置類型數據和標量類型綁定方法相同;②數組只支持Spring內置類型和標量類型的數據;③Spring MVC不支持將表單參數自動綁定在映射方法的集合參數,須要經過藉助一個JavaBean的類型隱性實現post
前端代碼this
<form action="${pageContext.request.contextPath}/zhangsan/login.action" method="post"> 密碼:<input name="psw" type="text"> <input type="submit" value="登陸"> </form>
後端代碼spa
1 @RequestMapping(value="/{username}/login",method=RequestMethod.POST) 2 public String login(@PathVariable String username, @RequestParam("psw") String password, @CookieValue(value="JSESSIONID") String cookie){ 3 System.out.println("-登陸-"+ cookie); 4 System.out.println("-用戶-"+ username); 5 return "/hello.jsp"; 6 }
前端代碼
<form action="${pageContext.request.contextPath }/login.mvc" method="post"> 用戶名:<input name="username" type="text"> 密碼:<input name="password" type="text"> <input type="submit" value="登陸"> </form>
後端代碼
1 @RequestMapping(value="login",method=RequestMethod.POST) 2 public String login(@RequestParam Map<String,Object> user){ 3 System.out.println("-登陸-"+ user.get("username")); 4 return "/hello.jsp"; 5 }
———————————————————————————————————————————————————————————————————
The end @ 萬有引力+
-
-
-
-
-