gpt4 book ai didi

java - Spring MVC @RequestMapping 不返回任何内容,只需关闭

转载 作者:太空宇宙 更新时间:2023-11-04 13:17:14 25 4
gpt4 key购买 nike

我正在开发一个收集信息的 JSP,提交后页面关闭,然后转到确认页面。我不需要确认页面。单击 JSP 上的“提交”后,我只想关闭窗口。 Controller 上的返回值需要一个值。我可以在那里放什么让它简单地结束?这是我的 Controller :

@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";
}
}

最佳答案

更改了 java Controller 中的方法以返回 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>

现在可以了。谢谢。

关于java - Spring MVC @RequestMapping 不返回任何内容,只需关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33444937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com