简体   繁体   English

Eclipse上的JSP:在条件语句中应用内联CSS

[英]JSP on eclipse: applying inline css in a conditional statement

I have a navigation bar in a .jsp file whereby I want it where if an imported java condition returns null then (using inline css), set the link in the navigation to display:none; 我在.jsp文件中有一个导航栏,我希望它在如果导入的Java条件返回null然后(使用内联CSS)的情况下,将导航中的链接设置为display:none; else display:block; else display:block; This is what I came up with so far but eclipse doesn't seem to like it when I add none and block: 这是我到目前为止提出的,但是当我不添加并阻止时,eclipse似乎并不喜欢它:

<li><a style="display:<%if(Settings.getInstance().getExternalDataLocation()!= null){
        none;" 
        }else{
        block;"}%> 
</li>

The following errors also seem to appear under the red lines of 'none' and 'block': 在“无”和“阻止”的红线下也似乎出现以下错误:

- Syntax error, insert "VariableDeclarators" to complete 
 LocalVariableDeclaration
- Syntax error on token "block", } expected
- Syntax error, insert ";" to complete BlockStatements

I'm sure the errors are self explanatory but I still cant seem to get my head round resolving them or even knowing if I am missing the correct syntax. 我确信这些错误是不言自明的,但是我仍然似乎无法解决这些错误,甚至无法知道我是否缺少正确的语法。 Hope someone can point me in the right direction. 希望有人能指出正确的方向。

Try this instead, 试试这个,

   <li>
        <%if(Settings.getInstance().getExternalDataLocation()!= null){%>
        <a style="display:none;">
        <%}else{%>
        <a style="display:block;">
        <%}%>        
    </li>

But however using scriptlets are considered to be bad since a decade . 但是自十年以来,使用scriptlet被认为是不好的。 try to use jstl or el 尝试使用jstl或el

see this post for more info How to avoid Java code in JSP files? 有关更多信息,请参见这篇文章。 如何避免JSP文件中的Java代码?

Hope this helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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