Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JakartaVelocity 1.7使用Spring MVC提交表单,在控制器中获取空值_Java_Spring_Forms_Spring Mvc_Velocity - Fatal编程技术网

Java JakartaVelocity 1.7使用Spring MVC提交表单,在控制器中获取空值

Java JakartaVelocity 1.7使用Spring MVC提交表单,在控制器中获取空值,java,spring,forms,spring-mvc,velocity,Java,Spring,Forms,Spring Mvc,Velocity,我从velocity生成一个表单,并将表单值提交给spring控制器。在spring控制器中,我得到了“null”值 表单:test.vm,使用@RequestMapping/testform和post方法提交调用控制器 <html> <body> <form method="POST" action="/testform"> Select testtype: <select name="test"> <option va

我从velocity生成一个表单,并将表单值提交给spring控制器。在spring控制器中,我得到了“null”值

表单:test.vm,使用@RequestMapping/testform和post方法提交调用控制器

<html>
  <body>
  <form method="POST" action="/testform">
  Select testtype:
  <select name="test">
  <option value="test1">test1</option> 
  <option value="test2">test2</option>
  </select>
  <p>
  <input type="submit" value ="submit">
  </form>
  </body>
  </html>

Controller code:

    @RequestMapping(value = "/testform", method = RequestMethod.POST)

    public ModelAndView addtest(@ModelAttribute("test")ReadTest test, BindingResult result) {

    System.out.println("in test controller");

    System.out.println("test:" + test.gettest());
    return new ModelAndView("test");
}
} }

提交表单值后,控制器中的test.gettest()返回“null” 你能帮我找出哪里做错了吗?感谢您的帮助。

添加commandName=“test”。它像是:

<form method="POST" action="/testform" commandName ="test">

您好,您必须为它添加命令名,如

<form method="POST" commandname="test" action="/testform"> 

此外,我认为您缺少ReadTest.java中的setter。请添加setter并检查一次。
请参考此示例代码。

谢谢,b/w,这里的测试是什么?是在@modeldattribute(“test”)中定义的名称吗?我仍然在cotroller中看到空值,commandName属性没有解决我的问题,还尝试了modeldattribute。
<form method="POST" commandname="test" action="/testform">