Spring MVC中如何打开Modal Jsp页面
我在 Web 应用程序中使用 Spring Mvc 和 Booststrap,我想将 editEmployer.jsp 页面显示为 Popup< /强>。下面是代码:
Page Index.jsp
<html>
<head>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
"url": "/employeesmanagement/api/employees/listEmplyees'",
"type": "GET",
"datatype": 'json',
"success": function (data) {
$('#employeesTable').DataTable({
data: data,
columns: [
{
title : 'id',
data : 'id'
}, {
title : 'name',
data : 'name'
},
{
"render": function (data, type, full, meta)
{ return '<a class="btn btn-xs btn-default" role="button" href="/editEmployer/' + data.id+ '">Edit</a>'; }
}
]
});
}
});
});
</script>
</head>
<body>
<table id="employeesTable" style="width: 100%"></table>
</body>
</html>
Controller
@Controller
@Transactional
@EnableWebMvc
public class EmployerController {
@RequestMapping("/editEmployer")
public String editEmployer(Model model, @RequestParam("id") String id) {
Employer employer = new Employer();
Repository repository = new Repository();
if (id != null) {
employer = repository.getEmployer(id);
}
model.addAttribute("employerModel", employer);
return "employerForm";
}
}
Employer page
<html>
<body>
<form:form action="saveEmployer method="POST" modelAttribute="employerModel">
<form:hidden path="id" />
<table>
<tr>
<td>Name</td>
<td><form:input path="name" /></td>
<td><form:errors path="name"></td>
</tr>
<tr>
<td>Email</td>
<td><form:input path="email" /></td>
</tr>
</table>
</form:form>
</body>
</html>
我知道我们可以使用 Boostrap 做到这一点,但是该方法需要将editEmployer.jsp页面的代码放在同一个页面Index.jsp中。如何打开editEmployer.jsp像弹出窗口一样的页面知道它位于与 index.jsp 页面不同的单独页面中?
感谢您的帮助。
I am using Spring Mvc and Booststrap in a web application and I would like to display the editEmployer.jsp page as a Popup. Below is the code:
Page Index.jsp
<html>
<head>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
"url": "/employeesmanagement/api/employees/listEmplyees'",
"type": "GET",
"datatype": 'json',
"success": function (data) {
$('#employeesTable').DataTable({
data: data,
columns: [
{
title : 'id',
data : 'id'
}, {
title : 'name',
data : 'name'
},
{
"render": function (data, type, full, meta)
{ return '<a class="btn btn-xs btn-default" role="button" href="/editEmployer/' + data.id+ '">Edit</a>'; }
}
]
});
}
});
});
</script>
</head>
<body>
<table id="employeesTable" style="width: 100%"></table>
</body>
</html>
Controller
@Controller
@Transactional
@EnableWebMvc
public class EmployerController {
@RequestMapping("/editEmployer")
public String editEmployer(Model model, @RequestParam("id") String id) {
Employer employer = new Employer();
Repository repository = new Repository();
if (id != null) {
employer = repository.getEmployer(id);
}
model.addAttribute("employerModel", employer);
return "employerForm";
}
}
Employer page
<html>
<body>
<form:form action="saveEmployer method="POST" modelAttribute="employerModel">
<form:hidden path="id" />
<table>
<tr>
<td>Name</td>
<td><form:input path="name" /></td>
<td><form:errors path="name"></td>
</tr>
<tr>
<td>Email</td>
<td><form:input path="email" /></td>
</tr>
</table>
</form:form>
</body>
</html>
I know we can do it with Boostrap, but this method requires to put the code of the page editEmployer.jsp in the same page Index.jsp .How can we open the editEmpoloyer.jsp page like a Popup knowing that it is in a separate page than the index.jsp page ?
Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
style="display: none;"
添加到popupPageDiv
并可以使用 javascript/jquery 显示隐藏。You can add
style="display: none;"
topopupPageDiv
and can show hide using javascript/jquery.我找到了答案,尽管没有具体的例子来解决 Spring MVC 的这种需求。因此,只需使用 Ajax 调用控制器的操作以及 Bootsrap 模态 Div 中的响应显示即可。
动作控制器的 Ajax 调用
Bootstrap modal div
希望这可以帮助任何遇到相同问题的人。
I found the answer, despite there are no specific examples that address this kind of need for Spring MVC. So just call the action of the controller with Ajax as well as the display of the response in a Bootsrap modal Div .
Ajax call of the action controller
Bootstrap modal div
Hope this helps anyone who is having the same issue.