controller如下:

 1 @RequestMapping(value=("/login"), method=RequestMethod.POST)
 2     public ModelAndView getUser(@RequestParam("loginName")String loginName,@RequestParam("passWord")String passWord,ModelAndView mv){
 3         User user1=userService.checkLogin(loginName, passWord);
 4         System.out.println(user1);
 5         if(user1!=null){
 6             mv.setViewName("redirect:/index");
 7         }
 8         else{
 9             mv.setViewName("forward:/userList");
10         }
11         return mv;
12     }

html登陆代码如下:

<div class="container">
      <form class="form-signin" method="post" action="login">
        <h2 class="form-signin-heading">Please sign in</h2>
       <!--  <label for="loginName" class="sr-only">LoginName</label> -->
        <input type="text"  required autofocus>
        
        <!--  <label for="passWord" class="sr-only">PassWord</label>-->
        <input type="password"  required>
        <input class="btn btn-lg btn-primary btn-block" type="submit" value="sign in"/>
      </form>

    </div> 

关于spring mvc传参错误 Required String parameter 'xxxxx' is not present

产生警告: Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'loginName' is not present]

 

检查代码发现参数无法传递,将input标签的id该为name

如下:

  name 属性规定 input 元素的名称。

  name 属性用于对提交到服务器后的表单数据进行标识,或者在客户端通过 JavaScript 引用表单数据。

注释:只有设置了 name 属性的表单元素才能在提交表单时传递它们的值。

相关文章:

  • 2021-07-26
  • 2021-08-04
  • 2021-05-19
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2021-11-26
  • 2021-09-02
  • 2021-07-06
  • 2021-08-13
  • 2022-12-23
相关资源
相似解决方案