我正在开发一个收集信息的JSP,然后在提交页面关闭后再转到确认页面。我不想要确认页面。在JSP上单击Submit后,我只想让窗口关闭。 Controller上的Return值需要一个值。我可以放在那里让它简单地结束? 这是我的控制器:
@Controller
//@SessionAttributes({"resultBoard", "filterBoard"})
public class NewEmployeeController {
NewEmployeeService newEmpService;
@Autowired
public NewEmployeeController(NewEmployeeService service){
this.newEmpService = service;
}
@RequestMapping(value = "NewEmpInput", method = RequestMethod.GET)
public String promptEmployee(Model model)
{
//JSP can only reference 1 object, but need to reference many objects. So I put many classes inside EmployeeFormWrapper wrapper class.
model.addAttribute("myForm", new EmployeeFormWrapper());
return "NewEmpInput";
}
@RequestMapping(value = "NewEmpInput", method = RequestMethod.POST)
public String newEmployee(@ModelAttribute("myForm") EmployeeFormWrapper myForm)
{
NewEmployeeVM employee = myForm.getEmployee();
ClientVM client = myForm.getClient();
ProjectVM project = myForm.getProject();
System.out.println("Employee = " + employee.getFirstName() + " " + employee.getLastName());
System.out.println("Client = " + client.getText());
System.out.println("Project = " + project.getText());
newEmpService.saveNewEmployee(employee);
return "ConfirmNewEmp";
}
}
答案 0 :(得分:0)
在java控制器中更改了方法以返回void。我将这个脚本添加到我的jsp:
<script type="text/javascript">
function closeWindow() {
window.close();
}
</script>
并在我的jsp中将表单的第一行更新为:
<form:form commandName="employee" modelAttribute="employee" onsubmit="closeWindow()">
我在jsp中的提交按钮保持不变:
<p>
<input type="submit" value="Submit">
</p>
现在它有效。感谢。