netbeans 7.0 在 Struts2 选择标记中显示错误.. netbeans 版本 6.9 不显示此错误

2022-01-16 00:00:00 netbeans-7 java struts2
<s:select
  name="PenaltyPercentage"
  id="PenaltyPercentageId"
  list="#{'7.5%':'7.5%', '15.0%':'15.0%'}" <!-- shows error in this line -->
  headerKey=""
  headerValue="Please Select"
  emptyOption="false">
</s:select>

错误信息如下所示

Encountered ":" at line 1, column 9.
Was expecting one of:
"}" ...
"." ...
"]" ...
">" ...
"<" ...

推荐答案

Netbeans 7 使用 JSP EL 2.1,它现在使用 # 字符.

Netbeans 7 uses JSP EL 2.1 which uses the # character now.

对我来说(Netbeans IDE 7.0 RC1)它编译得很好并且工作正常,尽管该行被标记为错误.如果 glassfish 不执行 jsp,则以下链接显示如何在 JSP 2.1 容器中禁用 JSP EL(以下链接的底部).

For me (Netbeans IDE 7.0 RC1) it compiles fine and works although the line is flagged with an error. If glassfish will not execute the jsp then the following link shows how to disable JSP EL in a JSP 2.1 container (bottom of the following link).

http://struts.apache.org/2.0.14/docs/ognl.html

这时候可能最简单的解决办法就是添加地图的类:

Probably the easiest solution at this time is to add the class of the map:

#@java.util.LinkedHashMap@{ "foo" : "foo value", "bar" : "bar value" } 

在此线程中找到:http://struts.1045723.n5.nabble.com/s2-JSF-JSP-EL-vs-OGNL-EL-td3528303.html

有关 JSP EL 2.1 的信息,请参阅:http://jcp.org/aboutJava/communityprocess/final/jsr245/index.html

For information on the JSP EL 2.1 See: http://jcp.org/aboutJava/communityprocess/final/jsr245/index.html

您可能只是在展示问题,但可以肯定的是,如果您提供列表而不是地图,则返回到服务器的值将与显示的值相同.所以下面会产生同样的选择框并且不会产生错误:

You are probably just showcasing the issue but just to be sure, if you supply a list rather than a map then the value returned to the server will be the same as the displayed value. So the following produces the same select box and does not produce an error:

<s:select
  list="{'7.5%','15.0%'}" <!-- does not show error -->
  headerValue="Please Select"
  emptyOption="false">
</s:select>

我花了一点时间看看是否可以在 Netbeans 7 中更改 JSP EL 版本但没有成功,还试图找到一种方法来禁用 JSP EL 错误检查但没有成功.因此,如果您必须在 JSP 中使用 OGNL 映射,请禁用 JSP EL(这对某些人来说不是一个有吸引力的选项)或显式声明该映射,如图所示.

I spent a little time seeing if I could change the JSP EL version in Netbeans 7 without success, also tried to find a way to disable JSP EL error checking without success. So if you must use OGNL maps in your JSP either disable JSP EL (which isn't an attractive option for some) or explicitly declare the map as shown.

相关文章