在已呈现的JSP中通过ajax请求加载spring表单 [英] Load spring form by an ajax request in already rendered JSP

查看:135
本文介绍了在已呈现的JSP中通过ajax请求加载spring表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个JSP已经呈现给客户端。在这个Jsp上,我创建了一个链接,我想要这个链接向服务器发出请求,服务器从命令对象中发送一个弹簧,这个弹簧形式在客户端已经加载的页面上呈现。我的意思是我不希望加载整个页面。我们采取的方式就像我的页面上有链接'更新联系人详细信息'。单击此链接会向服务器发出ajax请求,并从服务器发送spring表单,以便使用单击更新联系人详细信息链接的用户的联系详细信息填充表单。基本上我希望每次不必要地加载页眉和页脚之类的东西。

Let's say there is a JSP which has been rendered to the client. On this Jsp, I created a link, I want this link to make a request to the server and server sends a spring from with command object in it and this spring form gets rendered on the already loaded page on client. I mean I do not want whole page to be loaded. Let's take a scenario like there is link 'update contact details' on my page. Clicking on this link makes an ajax request to the server and spring form is sent from the server such that form is populated with the contact details of the user who clicked the link of 'update contact details'. Basically I want stuff like header and footer not to be loaded unnecessarily every time.

提前致谢。

推荐答案

如果您有链接,

<a id="screenId" href="#">

然后添加< div id =container>< / div> 你想要你的页面,也就是js函数,

then add <div id="container"></div> somewhere you want your page, also a js function as,

$('#screenId').click(function() {
    $.ajax({
         type: "GET",
         cache: false,
         url: "yourControllerURL",
         data: "",
         success: function(response){
             $('#container').html(response);
         }
    });
});

使用上面的ajax调用,在你的控制器内,用命令对象返回你的jsp。控制器代码可能看起来像这样。

with the above ajax call, inside your controller, return your jsp with the command object. The controller code may look something like this.

@RequestMapping(value="yourControllerURL") 
public String includeAnotherJSP(ModelMap model) {
    model.addAttribute("commandObjectName", commandObject);
    return "yourJSPMapping/jspName";
}

在您的控制器发送响应后,您将获得所需的JSP响应,然后您可以使用上面的js代码将其加载到< div id =container> 中。

After your controller will send the response, you will get the required JSP inside the response and you can then load that into your <div id="container"> using above js code.

这篇关于在已呈现的JSP中通过ajax请求加载spring表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆