JSP EL(表达式语言)在 Eclipse 中引起问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1790749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSP EL (Expression Language) causing problems in Eclipse
提问by Hymanocnr
My system: Ubuntu 9.10. Eclipse 3.5.1 with Java EE 1.2.1 (manual install - NOT from synaptic). Web Developer Tools 3.1.1
我的系统:Ubuntu 9.10。Eclipse 3.5.1 和 Java EE 1.2.1(手动安装 - 不是来自突触)。Web 开发人员工具 3.1.1
I've recently adopted someone else's code (a Dynamic Web Project), and run into lots of errors, warnings and incorrect syntax highlighting in Eclipse. I've narrowed it down to these 4 lines of code (create a new Dynamic Web Project, and then a new JSP page, and put this in the body):
我最近采用了别人的代码(一个动态 Web 项目),并在 Eclipse 中遇到了很多错误、警告和不正确的语法突出显示。我把它缩小到这 4 行代码(创建一个新的动态 Web 项目,然后一个新的 JSP 页面,并将其放在正文中):
${(1<2)? "" : "no"}
<%for (int i = 0; i < 5; i++) {%>
<div></div>
<%}%>
Errors / Warnings / Incorrect syntax highlighting
错误/警告/不正确的语法高亮
line1: yellow warning line under '<': Invalid character used in text string (${(1<2)? "yes" : "no"}).
line2: red error line under 'f': Multiple annotations found at this line: 1) Syntax error, insert "Finally" to complete TryStatement. 2) Syntax error, insert "}" to complete ClassBody
line2: red error line under ')': Syntax error on token ")", try expected after this token
line3: yellow warning line under 'div': No end tag (/div).
line3: yellow warning line under '<' of closing div: Multiple annotations found at this line: 1) Invalid character used in text string (${5} <%}%>). 2) Invalid character used in text string (${5} <%}%>).
line3: '/div' is black and purple (for scriptlet code?) instead of green for HTML code
line4: The opening and closing scriplet tags '<%' and '%>' are black instead of orange
第 1 行:'<' 下的黄色警告行:文本字符串中使用的字符无效 (${(1<2)? "yes" : "no"})。
第 2 行:'f' 下的红色错误行:在该行发现多个注释: 1) 语法错误,插入“Finally”以完成 TryStatement。2)语法错误,插入“}”完成ClassBody
第2行:')'下的红色错误行:令牌“)”上的语法错误,在此令牌后尝试预期
第 3 行:“div”下的黄色警告线:无结束标记 (/div)。
第 3 行:关闭 div 的“<”下的黄色警告行:在此行找到多个注释:1) 文本字符串中使用的字符无效 (${5} <%}%>)。2) 文本字符串中使用了无效字符 (${5} <%}%>)。
第 3 行:'/div' 是黑色和紫色(用于 scriptlet 代码?)而不是绿色用于 HTML 代码
第 4 行:开始和结束脚本标签 '<%' 和 '%>' 是黑色而不是橙色
The page works as expected in a browser: you get '5' five times. If you change the empty quotes on line 1 to "yes" then save, close the file in the editor, r click it in the project explorer > validate, then re-open it: all errors / warnings / incorrect syntax highlighting disappear, except the first one (invalid character). This is incredibly irritating. Any thoughts would be greatly appreciated.
该页面在浏览器中按预期工作:您得到五次“5”。如果将第 1 行的空引号更改为“是”然后保存,在编辑器中关闭文件,在项目资源管理器中单击它 > 验证,然后重新打开它:所有错误/警告/不正确的语法突出显示都会消失,除了第一个(无效字符)。这是令人难以置信的刺激。任何想法将不胜感激。
回答by BalusC
Eclipse WTP is great, but exactly this problem is an epic failin Eclipse WTP for me as well. They seem to be working on that, but until then I just disable/set-to-ignore all of the validation related to this stuff in the workspace preferences through Web> JSP Files> Validation> scroll list to very bottom and set all EL validation settings to Ignore. Also in the main Validationpreference uncheck all checkboxes related to JSP. This however doesn't seem to remove every warning/error, but it at least minimizes the annoyance.
Eclipse WTP 很棒,但这个问题对我来说也是 Eclipse WTP 中的一个史诗般的失败。他们似乎正在解决这个问题,但在那之前我只是通过Web> JSP 文件>验证> 滚动列表到最底部并设置所有 EL 验证在工作区首选项中禁用/设置为忽略所有与此相关的验证设置为忽略。同样在主验证首选项中,取消选中与 JSP 相关的所有复选框。然而,这似乎并没有消除每个警告/错误,但它至少可以最大限度地减少烦恼。
IntelliJ IDEAhandles JSP/EL validation much better.
IntelliJ IDEA 可以更好地处理 JSP/EL 验证。
To me, the symptoms make me think that WTP is using regexp instead of a stackbased parser to validate HTML/JSP/EL. This is a big no-noin case of structured markup.
对我来说,这些症状让我认为 WTP 正在使用正则表达式而不是基于堆栈的解析器来验证 HTML/JSP/EL。在结构化标记的情况下,这是一个很大的禁忌。