2017-09-06 82 views
2

我有一個html:無法從HTML將參數傳遞給控制器​​

<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
    <title>Insert title here</title> 
    </head> 
    <body> 
    <form name="AppE" method="post" action="http://10.18.9.10:8280/Ey/lin"> 
     <input type="text" name="userIdd" id="userIdd"><br/> 
     <input type="text" name="passwordd" id="passwordd"><br/> 
     <input type="text" name="appSerialNon" id="appSerialNon"><br/> 
     <input type="submit" name="Submit"> 
    </form> 
    </body> 
</html> 

/林去該控制器:

@RequestMapping(value = "/lin", method = RequestMethod.GET) 
public String login(@RequestParam(required=false, value="userIdd")String userIdd, @RequestParam(required=false, value="passwordd")String passwordd,@RequestParam(required=false, value="appSerialNon")String appSerialNon) { 
    System.out.println(userIdd+" "+passwordd+" "+appSerialNon); 
    return "login/login" 
} 

訪問HTML和填充值後,並提交我正在重定向到期望的頁面,但我在控制檯上得到空值,即我不能夠發送參數從HTML到控制器類。

回答

4

您的login()方法響應HTTP GET請求,但表單發送HTTP POST。使用RequestMethod.POST

0

您的形式發送POST請求

<form name="AppE" method="post" action="http://10.18.9.10:8280/Ey/lin">

所以讓你的控制器接受POST請求,變更method = RequestMethod.GETmethod = RequestMethod.POST

@RequestMapping(value = "/lin", method = RequestMethod.POST) 
public String login(@RequestParam(required=false, value="userIdd")String userIdd, @RequestParam(required=false, value="passwordd")String passwordd,@RequestParam(required=false, value="appSerialNon")String appSerialNon) { 
    System.out.println(userIdd+" "+passwordd+" "+appSerialNon); 
    return "login/login" 
} 
相關問題