gpt4 book ai didi

grails - 已经为此响应调用了Grails getWriter()

转载 作者:行者123 更新时间:2023-12-02 15:08:35 28 4
gpt4 key购买 nike

每当我在template.gsp中调用<ut:profilePicture>时,都会发生此错误。这是我的customTagLib

import rms.User

class userTagLib {
def springSecurityService
static namespace = "ut"

def fullName = {
User currentUser = springSecurityService.currentUser as User
if (currentUser) {
out << currentUser.firstName + " " + currentUser.lastName
}
}

def profilePicture ={
User currentUser = springSecurityService.currentUser as User
if (currentUser){
response.outputStream << currentUser.picture
}
}
}

我需要发布gsp代码吗?

最佳答案

您正在混合HTML和图片。您不能只将二进制图像放在HTML内,HTML只能包含指向该图像的链接。

您可以为个人资料图片制作带 Action 的Controller,例如:

def picture() {
User user = User.get(params.id)
response.contentType = ... // image/jpeg i guess?
response.outputStream << user.picture
return null
}

并将链接放在标签内:
def profilePicture ={
User currentUser = springSecurityService.currentUser as User
if (currentUser){
out << '<img src="'
out << createLink(controller: 'user', action: 'profile', id: currentUser.id)
out << '" alt="" />'
}
}

关于grails - 已经为此响应调用了Grails getWriter(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21282444/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com