有没有办法在当前页面的iframe中打开休息端点?

问题描述

[TL; DR结尾]

我们正在将一些基于旧jsp的组件升级到基于其余端点的棘手部分,那就是我们必须保持最终用户的行为不变。 我在jsp中使用jstl库。

一个包含iframe的页面,最初的iframe包含一个静态index.jsp页面,但是,当单击该网页上的超链接时,应该使用从jsp创建的特定其余端点的内容来更新iframe。

这是一个最小的例子 配置了初始其余端点的Java代码。

@GetMapping("defaultView")
   public ModelAndView defaultView(HttpServletRequest request,HttpServletResponse response) throws Exception {
   ModelAndView mav = new ModelAndView("defaultView");
   ... // populating mav object
   return mav;
}

defaultView.jsp的初始jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<body>
  <a href="messageCount">messageCount</a><br/> <%-- **This end-point should display resulted content in below iframe** --%>
  <br />
<%-- upon clicking hyperlink above messageCount,contents of messageCount.jsp supposed to be displayed in below iframe --%>
    <iframe src="${pageContext.request.scheme}://${node.identity.ipAddress}:${node.httpPort}${pageContext.request.contextPath}" width="100%" height="300">
    </iframe>
</body>
</html>

现在,正如我最初提到的那样,在上面的defaultView.jsp中单击 messageCount 时,我打算配置一个新的rest端点,以便显示(或使用其内容更新iframe)

messageCount端点,该端点返回ModelAndView对象,基于该对象创建jsp内容

@RequestMapping(value="messageCount",method = {RequestMethod.GET,RequestMethod.POST})
  public ModelAndView messageCount(Principal principal) {
   ModelAndView mav = new ModelAndView("messageCount");
   //populated mav with some fields and return
   return mav;
  }

messageCount.jsp在mav对象上包含一些操作,然后以HTML标记显示

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<!DOCTYPE html>
<html lang="en">
<body>
  <a href="${pageContext.request.contextPath}">Home</a>
  <%-- some <c:if>,<c:forEach> and <c:out> --%>
</body>
</html>

TL; DR

defaultView.jsp包含一个iframe,其余端点的mav(\messageCountmessageCount.jsp)的超链接应显示在iframe中。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...