javajsp

Java Server Page syntax error- what did I miss?


I Have the below mentioned Java Server Page code but it is showing syntax error with else token, I don't understand what is going wrong

<% if (isAliveMessage=="TIVOLI ALARM") {%>
<FONT COLOR="Red">
<p><b>Status of Alarm:<%= isAliveMessage  %></b></p>
</FONT>
<% } %>
<% else {%>
<p><b>Status of Alarm:<%= isAliveMessage %></b></p>
<% } %>

Solution

  • Though it'd be nice to see a bit more code, I suppose you're using some templating engine like underscore and you probably have an error in the 5th line. Should be:

    <% if (isAliveMessage=="TIVOLI ALARM") {%>
    <FONT COLOR="Red">
    <p><b>Status of Alarm:<%= isAliveMessage  %></b></p>
    </FONT>
    <% } else { %>
    <p><b>Status of Alarm:<%= isAliveMessage %></b></p>
    <% } %>
    

    Basically you should put your else statement in the same line with closing bracket.