一。使用request.getParameter("屬性名「)取值html
頁面代碼java
<form action="${basePath }doLogin.htm" method="post" onsubmit="check();"> 用戶名:<input name="username" type="text" id="un"><br><br> 密 碼:<input name="password" type="password" id="pwd"> <button type="submit">登錄</button> </form>
後臺代碼 app
@RequestMapping("/doLogin.htm") public String doLogin(HttpServletRequest req){ String u = req.getParameter("username"); System.out.println(u); return "/user/welcome"; }
二。使用註解方式傳值post
後臺代碼code
@RequestMapping("/doLogin.htm") public String doLogin(@RequestParam("username")String username){ System.out.println(username); return "/user/welcome"; }
三。參數傳值orm
後臺代碼htm
@RequestMapping("/doLogin.htm") public String doLogin(String username){ System.out.println(username); return "/user/welcome"; }
第二種比較適合用於form表單傳值,第三種能夠用於界面之間相互傳值,也方便開發人員利用AJAX傳值開發