Java 在对话框和div中加载jsp
我知道这可能是一个重复的问题,但我找不到这个简单问题的答案。我想在对话框和div中加载一个新的jsp文件Java 在对话框和div中加载jsp,java,javascript,jquery,jsp,Java,Javascript,Jquery,Jsp,我知道这可能是一个重复的问题,但我找不到这个简单问题的答案。我想在对话框和div中加载一个新的jsp文件 Structure: -WebContent -jsp -viewfolder -helloworld.jsp -helloworldedit.jsp -newworld.jsp 假设我有helloworld.jsp,它是从请求调度器加载的。我想在helloworld.jsp中的div标记中加载newworld.jsp 您必须等待
Structure:
-WebContent
-jsp
-viewfolder
-helloworld.jsp
-helloworldedit.jsp
-newworld.jsp
假设我有helloworld.jsp,它是从请求调度器加载的。我想在helloworld.jsp中的div标记中加载newworld.jsp
您必须等待DOM就绪事件:
请尝试以下代码:-
假设newworld.jsp中有一个div,其中包含要加载到helloworld.jsp中的另一个div中的所有数据
newworld.jsp
helloworld.jsp
或
您可以像这样使用JSP include标记
<div id="page" style="width:300px; height:300px;">
<jsp:include page="path of the page to be loaded"></jsp:include>
</div>
注意,在上面的代码中,您试图选择结果元素,而不是id=result的元素。有什么原因不能只使用服务器端包含吗?有什么错误吗?如果您的JS在JSP页面中,它是否包含在脚本标记中?您试图加载的JSP页面的绝对URL是多少?http://localhost:port/.projectcontext/jsp/viewfolder/helloworldedit.jsp 这应该是绝对URL。但是我无法打开jsp页面,那么您想使用URL/.projectcontext/jsp/viewfolder/helloworldedit.jsp或绝对URL,或者如果此页面与加载它的页面位于同一文件夹中,则为helloworldedit.jsp。我还尝试了{request.contextPath}/jsp/viewfolder/helloworldedit.jsp。这也没用。我得到的只是500个内部服务器错误,还有helloworldedit.jsp,它也不起作用。
<button id="button">button</button>
<div id="dialog"></div>
$('#button').on("click", function() {
$('#dialog').load('/jsp/viewfolder/helloworldedit.jsp').dialog();
});
http://localhost:port/.projectcontext/jsp/viewfolder/calendar.gif.
$(document).ready(function() {
$('#button').on("click", function() {
$('#dialog').load('/.projectcontext/jsp/viewfolder/helloworldedit.jsp').dialog();
});
});
<!doctype html>
<html>
<body>
<div id="target">
<!-- other HTML controls -->
</div>
</body>
</html>
<a href="#" onclick="loadPage();">Click Me</a>
<div id="page"></div>
<script>
function loadPage(){
$('#page').load('newworld.jsp #target');
or
// If you choose this method then give path of JSP to be loaded in
// anchor tag
$('#page').load($(this).attr('href'));
return false;
}
</script>
<div id="page" style="width:300px; height:300px;">
<jsp:include page="path of the page to be loaded"></jsp:include>
</div>