And*_*onQ 6 grails html-encode taglib
我使用的标签库,但它是像呈现,而不是输出性格怪异的行为,<,",和>它输出<,"和 >.
代码:
class LoginTagLib {
static defaultEncodeAs = [taglib:'html']
//static encodeAsForTags = [tagName: [taglib:'html'], otherTagName: [taglib:'none']]
def loginControl =
{
if(session.user)
{
out << "Hello ${session.user.name}"
out << """[${link(action:"logout", controller:"user"){"Logout"}}]"""
}
else
{
out << """[${link(action:"login", controller:"user"){"Login"}}]"""
}
}
Run Code Online (Sandbox Code Playgroud)
}
在.gsp我有
<g:loginControl />
Run Code Online (Sandbox Code Playgroud)
当我打开页面时,我有:
Hello Jane Smith[<a href="/Blogito/user/logout">Logout</a>]
Run Code Online (Sandbox Code Playgroud)
但页面的源代码是:
<div id="loginHeader">
Hello Jane Smith[<a href="/Blogito/user/logout">Logout</a>]
</div>
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用.encodeAsHTML(),decodeHTML,.replace('>', '<')和迄今没有奏效
您也可以告诉它将其作为文本(没有编码)发送更改
static defaultEncodeAs = [taglib:'html']
Run Code Online (Sandbox Code Playgroud)
至
static defaultEncodeAs = [taglib:'text']
Run Code Online (Sandbox Code Playgroud)