如何在 Spring MVC 中使用 AJAX 渲染视图

编程入门 行业动态 更新时间:2024-10-26 08:26:01
本文介绍了如何在 Spring MVC 中使用 AJAX 渲染视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 Spring MVC,我需要对服务器进行异步调用并仅刷新页面的一部分.

I'm using Spring MVC and I need to make an asynchronous call to the server and refresh only a piece of the page.

我实际拥有的是一个返回字符串的控制器.我使用 JQuery (.post()) 函数调用控制器.

What I actually have is a Controller that returns a String. I call the Controller using JQuery (.post()) function.

我的解决方案的问题是我无法像使用 ModelAndView 作为返回类型时那样呈现 JSP.

The problem with my solution is that I'm not able to render a JSP like I do when I use ModelAndView as return type.

有没有办法返回已经渲染的视图?

Is there any way to return a View already rendered?

提前致谢.

纽基诺

推荐答案

你可以把这个页面放到一个单独的 JSP 中,并从你的方法中返回一个指向它的 ModelAndView.从这一点来看,AJAX 调用和非 AJAX 调用之间没有区别.

You can put this piece of page into a separate JSP and return a ModelAndView pointing to it from your method. There are no difference between AJAX and non-AJAX calls from that point.

更多推荐

如何在 Spring MVC 中使用 AJAX 渲染视图

本文发布于:2023-11-15 10:37:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593675.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   如何在   MVC   Spring   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!