[英]How to include jsp file inside another jsp file using jQuery
I am trying to include a jsp file when a button is clicked like so当一个按钮被点击时,我试图包含一个jsp文件
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#RegisterChildPage').on('click', function() {
$('.content').html("<%@ include file="FamilyManagerView.jsp"%>");
});
});
</script>
My problem is in this line $('.content').html(<%@ include file="FamilyManagerView.jsp"%>);
我的问题是在这一行
$('.content').html(<%@ include file="FamilyManagerView.jsp"%>);
There is a syntax error and i don't know what is the correct way to write it.有一个语法错误,我不知道什么是正确的写法。
<%@ include file="FamilyManagerView.jsp"%>
is not included properly because of the <% %>
. <%@ include file="FamilyManagerView.jsp"%>
由于<% %>
未正确包含。
This may help you.这可能对你有帮助。
Add a DIV to your JSP file which includes your other JSP file and it is initially hidden将 DIV 添加到包含其他 JSP 文件的 JSP 文件中,并且最初是隐藏的
Then remove hidden in onlclick function然后删除隐藏在onlclick函数中
!document.getElementById('testContainer').hidden
- The HTMLElement property hidden is a Boolean which is true and using ! !document.getElementById('testContainer').hidden
- HTMLElement 属性 hidden 是一个布尔值,它是 true 并且使用 ! operator you can display the hidden DIV.操作符可以显示隐藏的DIV。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Main JSP</title> </head> <body> <div class="row"> <div class="col-12"> <div class="row"> <button class="btn btn-success" onclick="renderElement()">Render Me</button> </div> <div class="row mt-2" id="testContainer" hidden> <!-- Insert your file here --> <%@ include file="test.jsp" %> </div> </div> </div> </body> <script> const renderElement = () => { document.getElementById('testContainer').hidden = !document.getElementById('testContainer').hidden; } </script> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.