【发布时间】:2017-05-27 15:50:31
【问题描述】:
您好,我需要将表单中的隐藏值之一获取到我的控制器。我怎么才能得到它。请在下面找到我的代码。我需要在我的控制器中获取隐藏值的值`
@RequestMapping("/submitAdmissionForm.html",method = RequestMethod.POST)
public ModelAndView submitAdmissionForm(@RequestParam("studentName") String name, @RequestParam("studentHobby") String hobby) {
ModelAndView model = new ModelAndView("AdmissionSuccess");
model.addObject("msg","Details submitted by you:: Name: "+name+ ", Hobby: " + hobby);
return model;
}
`
JSP 页面
<html>
<body>
<h1> STUDENT ADMISSION FORM FOR ENGINEERING COURSES</h1>
<form action="/submitAdmissionForm.html" method="post">
<p>
Student's Name : <input type="text" name="studentName" />
</p>
<p>
Student's Hobby : <input type="text" name="studentHobby" />
</p>
<input type="hidden" id="Student" value="Sree" />
<input type="submit" value="Submit this form by clicking here" />
</form>
</body>
</html>
【问题讨论】:
-
隐藏输入与任何其他输入一样。获取
studentName的相同方式可用于检索Sree的值。 -
只需在您的输入中添加名称属性,例如: 之后你可以用同样的方式处理它你像另一个参数一样申请
标签: javascript java spring jsp spring-mvc