Spring Boot Thymeleaf模板图像源属性格式错误,需要符合RFC 7230和RFC 3986

holgip5t  于 2022-11-05  发布在  Spring
关注(0)|答案(1)|浏览(78)

下面的代码是在我的Thymeleaf模板:

<form action="#" th:object="${userDto}" method="post">
...
<img alt="" src="@{/ProfileImageServlet?imageId=*{profileImageId}}"
                             width="100" style="border-radius: 50%;" >

其中,ProfileImageServlet应该使用参数 *{profileImageId}(userDto中的属性)中的图像ID动态生成图像。但是,这并没有发生。应用程序失败,并显示以下错误:

java.lang.IllegalArgumentException: Invalid character found in the request target [/@%7B/ProfileImageServlet?imageId=*{profileImageId}} ]. The valid characters are defined in RFC 7230 and RFC 3986

请帮帮忙。

yebdmbv4

yebdmbv41#

您需要使用th:src,而不是src

<img alt="" th:src="@{/ProfileImageServlet?imageId=*{profileImageId}}"
                             width="100" style="border-radius: 50%;" >

相关问题