我已经为项目创建了一个用Java编写的登录系统,现在我想在JSP页面上的Java代码中显示Twitter Bootstrap的模态。那可能吗?我尝试过调用Javascript函数,但这不起作用,因为Javascript是客户端而Java是服务器端。
我已尝试在Java中打印脚本标记,但这也不起作用。我也可以用Java打印模态,但我不能解雇它。
我尝试显示的模式:
<!-- Login Modal -->
<div class="modal fade" id="loginmodal" tabindex="-1" role="dialog" aria-labelledby="loginmodallabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="loginmodallabel"> Sample Title</h3>
</div>
<div class="modal-body">
<p>Sample Text</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-block" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Java代码
//Checks if the username and password exist for the current selected building
if(LoginDao.validate(name, pass, build, session))
{
response.sendRedirect("/bigdata/dashboard.jsp");
}
else{
// I want to show the modal here
rd= request.getRequestDispatcher("login.jsp");
rd.include(request,response);
}
供参考: Twitter Bootstrap模式:http://getbootstrap.com/javascript/#modals
答案 0 :(得分:0)
您可以在JSP中打印将在页面加载上运行的代码。在java代码确定需要显示模式后,这将在页面上显示。:
<script type="text/javascript">
$(document).ready( function(){
$("#loginmodal").modal();
} );
</script>