在对话框和div中加载一个jsp [英] load a jsp in a dialog and div
问题描述
我知道这可能是一个重复的问题,但是我找不到这个简单问题的答案.我想在对话框和div中加载新的jsp文件.
I know this might be a duplication question, but I couldn't find the answer for this simple question. I want to load a new jsp file in a dialog and a div.
Structure:
-WebContent
-jsp
-viewfolder
-helloworld.jsp
-helloworldedit.jsp
-newworld.jsp
假设我有helloworld.jsp
,它是从请求分派器加载的.我想在helloworld.jsp
的div标签中加载newworld.jsp
.
let's say I have helloworld.jsp
which is loaded from request dispatcher. I want to load newworld.jsp
in a div tag in helloworld.jsp
.
<div id="result"></div>
$('#result').load('/jsp/viewfolder/newworld.jsp');
尝试了上面的代码,没有用.
Tried the above code, didn't work.
我还试图将一个jsp页面加载到一个对话框中,而这个对话框也失败了.
I have also tried to load a jsp page into a dialog and this one has failed too.
<button id="button">button</button>
<div id="dialog"></div>
$('#button').on("click", function() {
$('#dialog').load('/jsp/viewfolder/helloworldedit.jsp').dialog();
});
我的问题是,这是调用jsp页面的正确方法,还是我必须使用ajax从请求分派器加载页面.
The question I have is, this is the right way to call the jsp page or do I have to load the page from request dispatcher using ajax.
要测试路径是否正确,我尝试将calendar.gif
放在同一文件夹中,并能够从上下文中访问它.
To test if the path is correct, I tried to put a calendar.gif
in the same folder and I was able to reach it from the context.
http://localhost:port/.projectcontext/jsp/viewfolder/calendar.gif.
推荐答案
尝试以下代码:-
假设您在newworld.jsp
中有一个div
,其中包含要加载到helloworld.jsp
Suppose you have a div
in newworld.jsp
which contains all data which you want to load in another div
which is present in helloworld.jsp
newworld.jsp
<!doctype html>
<html>
<body>
<div id="target">
<!-- other HTML controls -->
</div>
</body>
</html>
helloworld.jsp
<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>
OR
您可以像这样使用 JSP包含标签
<div id="page" style="width:300px; height:300px;">
<jsp:include page="path of the page to be loaded"></jsp:include>
</div>
这篇关于在对话框和div中加载一个jsp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!