当从控制器返回url时,图像源未知

问题描述 投票:0回答:1

我是一个Ui设计的新手,我想用JSP和spring boot写一个简单的应用程序,我的想法是在控制器中获取Google QR码的URL并返回到JSP页面。

https://chart.googleapis.com/chart?chs=200x200&chld=M%%7C0&cht=qr&chl=otpauth%3A%2F%2Ftotp%2FSpringRegistration%3Atest_user%3Fsecret%3DI2S5OTJXDG5NBWVY%26issuer%3DSpringRegistration

所以,我的控制器看起来像下面。

@GetMapping("/confirmRegistration")
public String confirmRegistration(final HttpServletRequest request,
                                  final Model model) {
    final User user = userService.getUser(token);
    String qrUrl = userService.generateQRUrl(user);
    log.info("QR URL: {}", qrUrl);
    model.addAttribute("qr_code", qrUrl);
    return "redirect:/qrcode";
}

我的JSP看起来像-

<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="en">
  <head>
    <title>Confirm your account</title>
  </head>
  <body>
    <label>Scan following QR code.</label>
    <c:if test="${param.url != null}">
        <span> hi there </span>
        ${param.url}
    </c:if>
    <c:url value="${qr_code}" />
    <img src="${qr_code}" width=256 height=256 />
    <br />
    <img src="${param.qr[0]}"/>
  </body>
</html>

但它没有填充图片。UI页面如下图所示。enter image description here

谁能帮帮我?

spring-boot jsp model-view-controller jstl
1个回答
0
投票

我想,这个问题与以下几点有关 return 语句。你应该点一个你的jsp页面的名字,把带有图片url的模型转发到。但在此之前,你需要定义和配置 InternalResourceViewResolver

更多信息 (转向 转发)

© www.soinside.com 2019 - 2024. All rights reserved.