在 Struts2 中使用 jQuery 模板

发布于 2024-11-25 10:09:14 字数 603 浏览 0 评论 0原文

我正在尝试使用 Struts2 更新页面(使用 jOWL 显示本体)。原始 HTML 页面使用 jQuery 模板,有几行,例如:

<h2 class="propertybox title" data-jowl="rdfs:label">${rdfs:label}</h2>
<span class="alt">${?p}</span><span>: </span><span>${?t}</span>

显示 jQuery 脚本文件中确定的变量。作为 .html 文件,这已经足够好了。然而,.jsp 文件认为我正在尝试使用 Struts 变量而不是 jQuery 模板。当遇到冒号和问号时它会崩溃。

我确实找到了一些 jQuery Struts2 库,但我没有看到任何映射到 jQuery 模板的标签。还有其他方法可以做到这一点吗?

I am attempting to update a page using Struts2 (using jOWL to display an ontology). The original HTML page uses jQuery templates, having several lines such as:

<h2 class="propertybox title" data-jowl="rdfs:label">${rdfs:label}</h2>
<span class="alt">${?p}</span><span>: </span><span>${?t}</span>

to display a variable determined in a jQuery script file. This works well enough as a .html file. However, the .jsp file thinks I am attempting to use Struts variables rather than a jQuery template. It crashes when it encounters the colon and question mark.

I did find some jQuery Struts2 libraries, but I didn't see any tags that would map to jQuery templates. Is there another way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小嗷兮 2024-12-02 10:09:14

你的问题是jsp认为${}是EL。因此,您需要以某种方式转义部分表达,这不会很漂亮:

From the JSP 2 spec:

For literal values that include the character sequence ${, JSP 2.0 provides a
way to escape them by using the sequence ${'${'. For example, the following
character sequence is translated into the literal value ${expr}:

${'${'}expr}

来源:http://www.velocityreviews.com/forums/t129212-ot-jsp-escape-el-expressions.html

Your issue is that a jsp thinks ${} is EL. So you need to somehow escape part of the express, this isn't going to be pretty:

From the JSP 2 spec:

For literal values that include the character sequence ${, JSP 2.0 provides a
way to escape them by using the sequence ${'${'. For example, the following
character sequence is translated into the literal value ${expr}:

${'${'}expr}

Source: http://www.velocityreviews.com/forums/t129212-ot-jsp-escape-el-expressions.html

街角迷惘 2024-12-02 10:09:14

关于 EL 和建议的模式:

${'${'}expr}

根据 Oracle,您可以禁用 EL 解析: 停用 EL 表达式计算

<%@ page isELIgnored ="true|false" %> 

由于在 JSP 2.0 之前的 JSP 规范中未保留标识 EL 表达式的模式 - ${ } -,因此可能存在需要逐字传递此类模式的应用程序。为了防止模式被评估,您可以停用 EL 评估。

该属性的有效值为 true 和 false。如果为 true,则 EL 表达式出现在静态文本或标记属性中时将被忽略。如果为 false,则由容器计算 EL 表达式。

In regards to EL and the suggested pattern:

${'${'}expr}

According to Oracle you can disable the EL parsing: Deactivating EL Expression Evaluation

<%@ page isELIgnored ="true|false" %> 

Because the pattern that identifies EL expressions--${ }--was not reserved in the JSP specifications before JSP 2.0, there may be applications where such a pattern is intended to pass through verbatim. To prevent the pattern from being evaluated, you can deactivate EL evaluation.

The valid values of this attribute are true and false. If it is true, EL expressions are ignored when they appear in static text or tag attributes. If it is false, EL expressions are evaluated by the container.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文