简体   繁体   English

使用JSP从Java返回CSS类样式

[英]Using JSP to return a CSS class style from Java

I'm new to JSP so with this question I'm really just wondering if I have right idea about how JSP works. 我是JSP的新手,所以我真的想知道我是否对JSP的工作原理有正确的认识。 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. 但是无论如何,我正在开发这个Web应用程序,在其中我需要用一些值填充表格,并用绿色将其中一些颜色,红色,有些是灰色。 What color they have is determined by the Java object that backs all of the values for each row. 它们具有什么颜色由支持每行所有值的Java对象确定。 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="". 在网页的源代码中,类仅显示class =“”。 So am I missing the point of how JSP works? 我是否错过了JSP的工作原理? 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. 编辑:还有一个附加的类属性getClassStyle()返回,它指示单元格所在的列。诸如此类:td class =“ detail red”> Down因此,仅将其着色为红色不是我想要的。

Well youre missing the = in your post, but im not sure if thats just a typo here or in your actual JSP. 好吧,您在您的帖子中缺少了= ,但是我不确定这是否只是此处或您实际的JSP中的错字。

Secondly, scriptlet syntax is evil as Pointy mentioned in his comment. 其次,正如Pointy在评论中提到的那样,scriptlet语法是邪恶的。 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() ). 现在,我不确定在Java端如何设置对象,但想像一下您需要确保设置一些连线,以便尝试访问detail.whatever调用正确的getter( detail.getWhatever() )。

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

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