在对话框和div中加载jsp

enyaitl3  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(148)

我知道这可能是一个重复的问题,但我找不到这个简单问题的答案。我想在对话框和div中加载一个新的jsp文件。

Structure:
 -WebContent
   -jsp
     -viewfolder
       -helloworld.jsp
       -helloworldedit.jsp
       -newworld.jsp

假设我有一个从请求分配器加载的helloworld.jsp,我想在helloworld.jsp的div标签中加载newworld.jsp

<div id="result"></div>

$('#result').load('/jsp/viewfolder/newworld.jsp');

已尝试上述代码,但无效。
我也尝试过将jsp页面加载到对话框中,这个也失败了。

<button id="button">button</button>
<div id="dialog"></div>

$('#button').on("click", function() {
        $('#dialog').load('/jsp/viewfolder/helloworldedit.jsp').dialog();
    });

我的问题是,这是调用jsp页面的正确方式,还是必须使用 AJAX 从请求调度器加载页面。
为了测试路径是否正确,我尝试将一个calendar.gif放在同一个文件夹中,我能够从上下文中访问它。

http://localhost:port/.projectcontext/jsp/viewfolder/calendar.gif.
atmip9wb

atmip9wb1#

您必须等待DOM ready事件:

$(document).ready(function() {
    $('#button').on("click", function() {
        $('#dialog').load('/.projectcontext/jsp/viewfolder/helloworldedit.jsp').dialog();
    });
});
xj3cbfub

xj3cbfub2#

  • Try below code :-*

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

You can use JSP include tag like this

<div id="page" style="width:300px; height:300px;">  
    <jsp:include page="path of the page to be loaded"></jsp:include>  
</div>

相关问题