Ответ 1
Вы можете использовать @RequestParam
следующим образом:
@RequestMapping(value="/forgotpassword", method=RequestMethod.POST)
public String recoverPass(@RequestParam("j_username") String username) {
//do smthin
}
Я использую Spring MVC. Как я могу получить значение текстового поля следующего фрагмента в моем методе контроллера?
<form name="forgotpassord" action="forgotpassword" method="POST" >
<ul>
<li><label>User:</label> <input type='text' name='j_username' /></li>
<li><label> </label> <input type="submit" value="OK" class="btn"></li>
</ul>
</form>
Вы можете использовать @RequestParam
следующим образом:
@RequestMapping(value="/forgotpassword", method=RequestMethod.POST)
public String recoverPass(@RequestParam("j_username") String username) {
//do smthin
}
1. Use Form tag library
Just add
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<form:form name="forgotpassord" action="forgotpassword" method="POST">
<ul>
<li><label>User:</label> <input type='text' name='j_username' /></li>
<li><label> </label> <input type="submit" value="OK" class="btn"></li>
</ul>
</form:form>
2. Now in controller
@RequestMapping(value="/forgotpassword", method = RequestMethod.POST)
public ModelAndView forgotpassword(@ModelAttribute("FormJSP_Name") User user,BindingResult result) {
String user = user.getjUsername(); //use it further
ModelAndView model1 = new ModelAndView("NextJSP_Name");
return model1;
}