开发者

Using jQuery Templates in Struts2

开发者 https://www.devze.com 2023-03-22 01:56 出处:网络
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:

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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号