1

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; 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:

<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.

2
  • 1
    I guess you have a misplaced ". Try this: style="display:'<%if(Settings.getInstance().getExternalDataLocation()!= null){ none; }else{ block;}%'"> Commented Jul 14, 2014 at 10:39
  • I guess you have a misplaced ". Try this: style="display:<%if(Settings.getInstance().getExternalDataLocation()!= null){ none; }else{ block;}%"> Commented Jul 14, 2014 at 10:57

1 Answer 1

2

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 . try to use jstl or el

see this post for more info How to avoid Java code in JSP files?

Hope this helps!!

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you everyone for the quick responses. I have tried your solution san and it has worked successfully and is far more comprehensible then my initial idea. I did not realise how much scriptlets are discouraged and deliver such limitations. I probably will look more into the alternatives you have mentioned to avoid hindering my project as a whole. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.