小编And*_*onQ的帖子

TagLib输出错误的编码

我使用的标签库,但它是像呈现,而不是输出性格怪异的行为,<,",和>它输出&lt;,&quot;&gt;.

代码:

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[&lt;a href=&quot;/Blogito/user/logout&quot;&gt;Logout&lt;/a&gt;]
</div>
Run Code Online (Sandbox Code Playgroud)

我已经尝试使用.encodeAsHTML(),decodeHTML,.replace('&gt;', '<')和迄今没有奏效

grails html-encode taglib

6
推荐指数
2
解决办法
1854
查看次数

标签 统计

grails ×1

html-encode ×1

taglib ×1