我有一个当前仅具有文本输入字段的表单。用户有3个关于如何处理输入的选项:
当前,只有“发送”按钮可以正常使用。 “清除”和“查看结果”按钮完全没有响应,但是显示在页面上并且可以单击。
有什么想法可以解决最后2个按钮吗?
<body>
<p>
<a href='/NewTest'>New Test upload</a>
</p>
<div>
<form th:action="@{/sendTest}" th:object="${Test}" method="post">
<label for="name" id="name" >Name</label>
<input type="text" id="name" name="name"/>
<input type="submit" name="action" value="Send"/></form>
<input type="submit" name="action" value="Clear"/></form>
<input type="submit" name="action" value="See Results"/></form>
<br>
</div>
<a> Current test for students: </a>
<p th:text="${currentTest}" ></p>
<div>
<a>Available tests for students:</a>
<th:block th:each="test : ${tests}">
<tr>
<td th:text="${test.getName()}">...</td>
<td th:text="${test.getFile().getName()}">...</td>
</tr>
</div>
</body>
控制器
@Controller
public class TeacherController {
TestController testcont = TestController.getInstance();
@RequestMapping(value = {"/Teacher"}, method = RequestMethod.GET)
public String teacher(Model model) {
model.addAttribute("Test", new Test());
model.addAttribute("tests", testcont.showAllTests());
model.addAttribute("currentTest", testcont.getActiveTest());
return "Teacher";
}
@RequestMapping(value = {"/sendTest"}, method = RequestMethod.GET)
public String currentTestOptions(Model model) {
model.addAttribute("Test", new Test());
model.addAttribute("tests", testcont.showAllTests());
model.addAttribute("currentTest", testcont.getActiveTest());
return "Teacher";
}
@RequestMapping(value = {"/sendTest"}, method = RequestMethod.POST, params="action=Send")
public String sendTest(@Valid @ModelAttribute("test") Test test, BindingResult bindingResult, Model model){
for(Test i : testcont.showAllTests()){
if(i.getName().equals(test.getName())) {
testcont.SetActiveTest(i);
model.addAttribute("currentTest", testcont.getActiveTest());
}
}
return "sendTest";
}
@RequestMapping(value = {"/sendTest"}, method = RequestMethod.POST, params="action=Clear")
public String clearTest(){
testcont.SetActiveTest(null);
return "Teacher";
}
//***********Test Results************
@RequestMapping(value = {"/TestResults"}, method = RequestMethod.GET)
public String testResultsData(@Valid @ModelAttribute("test") Test test, BindingResult bindingResult, Model model){
model.addAttribute("Students", testcont.showAllStudents());
return "TestResults";
}
@RequestMapping(value = {"/sendTest"}, method = RequestMethod.POST, params="action=See Results")
public String testResults(@Valid @ModelAttribute("test") Test test, BindingResult bindingResult, Model model){
for(Test i : testcont.showAllTests()){
if(i.getName().equals(test.getName())) {
model.addAttribute("Answer", i.getStudentAnswer());
}
}
return "TestResults";
}
}