1

I'm new to JSP so with this question I'm really just wondering if I have right idea about how JSP works. But anyway, I'm developing this web app where I need to fill a table with some values and color some of them green, some of them red, and some of them gray. What color they have is determined by the Java object that backs all of the values for each row. So this was my idea:

<td class="<%detail.getClassStyle()%>"><%= detail.getStatus() %></td>

which I had hoped would have turned out like this after the methods returned:

<td class="red">Down</td>

But it doesn't work. In the web page's source code class just says class="". So am I missing the point of how JSP works? And whether I am or not, could someone propose an idea of how to get my intended result?

Edit: There's also an additional class attribute getClassStyle() returns which denotes the column the cell is in. Something like: td class="detail red">Down So simply just coloring it red is not something I'd like to do.

3
  • 1
    If you're just now starting to learn JSP, you need to immediately unlearn that "scriptlet" syntax and learn JSTL/EL instead. What you're doing has been deprecated for years. (You left off the "=" sign in the "class" value above.) Commented Oct 30, 2012 at 12:48
  • Ah, okay. I just googled "JSP tutorial" and took one of the first links. If you mean I'm missing the = in <%detail.getClassStyle()%>, that also did not work. Commented Oct 30, 2012 at 12:53
  • For web technology, it's a good idea to never trust a resource that's more than a couple years old :-) Things change really fast. And JSTL/EL, while far from perfect, is a much cleaner way of constructing page templates. If <%= detail.getClassStyle() %> doesn't work, then perhaps the problem is on the Java side of the fence. Commented Oct 30, 2012 at 12:57

1 Answer 1

1

Well youre missing the = in your post, but im not sure if thats just a typo here or in your actual JSP.

Secondly, scriptlet syntax is evil as Pointy mentioned in his comment. use:

<td class="${detail.classStyle}">${detail.status}</td>

Now im not sure how your object is set up on the java side but imagine there is some wiring you need to insure is set up so that attempting to access detail.whatever calls the proper getter (detail.getWhatever()).

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

2 Comments

Do you mean I should have <%=detail.getClassStyle()%> ? Because that also did not work.
I did... but im saying you should not use that printing syntax AT ALL.

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.