-1

I am trying to print the status in different colours using bootstrap but this prints nothing. Please can somebody help to figure out my mistake.

<% if (a.getStatus() == "OnTime")
{%>
<td class="btn-success"><%= a.getStatus()%></td>  
<% } else if (a.getStatus() == "Delayed")
{%> <td class="btn-warning"><%= a.getStatus()%></td>  
<% } else if (a.getStatus() == "Canceled")
{%> <td class="btn-danger"><%= a.getStatus()%></td>  F
<% } else
{ %> <td> </td> <% } %>
Rushabh Shah
  • 405
  • 1
  • 6
  • 16
  • 1
    Maybe it's about time java compiler throw a warning when someone attempts to compare a string with `==`. Newbies always stumbles here.. – gerrytan Nov 17 '14 at 22:39
  • 1
    Two main problems: 1) Use `equals` rather than `==` to compare `String`s. 2) [**Don't use scriptlets, it's discouraged**](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files). Instead, use Expression Language and libraries like JSTL where you can effectively compare strings by using `==` with no problems. – Luiggi Mendoza Nov 17 '14 at 22:46

1 Answers1

0

Maybe status is not initialized.

You must compare string content with

<% if (a.getStatus().equals("OnTime") )

Or

<% if (a.getStatus().equalsIgnoreCase("OnTime") )

And just for debugging in last line put

{ %> <td> <%= a.getStatus()%> </td> <% } %>

to see de actual status method result.