2017-09-06 92 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" 
} 
相关问题