简体   繁体   中英

Why does Eclipse complain about missing semicolon in my javascript?

I'm having an issue with Eclipse where it's complaining about missing semicolons in javascript code in a jsp file. Given the two lines below, Eclipse complains about the first line and indicates that there's a missing semicolon right before the closing curly brace. It has no complaints about the second line. I'd prefer to use the first way, but I'm annoyed with the warnings. Is there a different syntax that I should be using? I'm also using JQuery, so I don't know if this is contributing to the parsing error in Eclipse.

var isFoo = ${actionBean.isFoo};  // javascript type is boolean

var isFoo = '${actionBean.isFoo}';  // javascript type is string

To answer some of the questions people have posed in the comments...

This code is from a JSP file and actionBean refers to the Java action bean for this page. "isFoo" is a member variable of the action bean. The syntax ${actionBean.isFoo} is JSP Expression Language (or EL for short) and it's used to evaluate a java variable in a JSP. In this case, my code takes the value from the java variable and assigns it to the javascript variable. The code works just fine, but Eclipse complains.

var isFoo = ${actionBean.isFoo};

This is not valid JavaScript, which is why you're getting a syntax error. I'm assuming the ${...} is supposed to do some interpolation in NetBeans, but Eclipse has no way of knowing that, and just tries to parse it as JavaScript. Unless there's an Eclipse plugin or setting for dealing with mixed code like this, you may just have to deal with seeing syntax errors.

Eclipse is complaining because it is not really Javascript, and it is trying to parse it like Javascript. If it is really annoying you could disable the warning in the preferences, under your own risk to not be notified in other circumstances:

禁用分号

var isFoo = ${actionBean.isFoo};

不是javascript,而是JSF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM