【发布时间】:2020-09-06 05:45:26
【问题描述】:
我是 Ui 设计的新手,我正在尝试使用 JSP 和 Spring Boot 编写简单的应用程序。 思路是在控制器中获取谷歌二维码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>
有人可以帮我吗?
【问题讨论】:
-
log.info("QR URL: {}", qrUrl);给了什么?这是否为 nqrUrl提供了正确的值? -
是的,它会打印网址,如果我在浏览器中打开该网址,我可以看到二维码。
标签: spring-boot spring-mvc jsp