0
我有jsp文件並試圖從兩個文本字段插入值。我使用<form:input path="name" />
進行輸入,但運行時不顯示文本字段(圖1)。表單輸入文本字段不起作用
<form:form method="POST" commandName="student">
<table>
<tr>
<td>Enter your name:</td>
<td><form:input path="name" /></td>
<td><form:errors path="name" cssStyle="color: #ff0000;"/></td>
</tr>
<tr>
<td>Enter your last name:</td>
<td><form:input path="lastName" /></td>
<td><form:errors path="lastName" cssStyle="color: #ff0000;"/></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
<tr>
</table>
</form:form>
學生控制器
@Controller
@RequestMapping("/student.htm")
public class StudentController {
@Autowired
@Qualifier("studentValidator")
private Validator validator;
@InitBinder
private void initBinder(WebDataBinder binder) {
binder.setValidator(validator);
}
@RequestMapping(method = RequestMethod.GET)
public String initForm(Model model){
Student student = new Student();
model.addAttribute("student", student);
return "student";
}
@RequestMapping(method = RequestMethod.POST)
public String submitForm(
Model model, @Validated Student student, BindingResult result) {
String returnVal = "success";
if(result.hasErrors()) {
returnVal = "student";
} else {
model.addAttribute("student", student);
}
return returnVal;
}
}
圖片1
我接着說:<%@ taglib'和tested.now了500錯誤(發生異常處理JSP頁面[/index.jsp]在[12]行)。在第12行顯示'
yes!你正確的,你需要從你的控制器傳遞命令名(學生) –
我編輯了我的文章,我完全是新的這個,我怎麼傳遞命令? – Tje123