日期:2014-05-18  浏览次数:20788 次

求:jsp页面上按得到不同的信息显示不同的颜色的问题
比方说在jsp上有一条select语句
然后
<%
while(rs.next()){
hth=rs.getString( "aa ");}
%>
在下面显示
<td> <div   align= "left "> <%=aa%> </div> </td>

请问我如果想按不同的aa内容用不同的颜色(字体或背景颜色都可)显示在页面上

此if判断语句应如何写,放在哪??

------解决方案--------------------
最好的办法是写个资源文件,在里面设定颜色.例如:1=red;
在jsp页面上用switch();
这样写有利于维护.
------解决方案--------------------

通过sql可以按照内容得到数据集合
不过没必要而且 效率会慢~
楼上的建议很好~

------解决方案--------------------
写个css文件,根据不同的aa内容调用用不同的css
------解决方案--------------------
<%
while(rs.next()){
hth=rs.getString( "aa ");}
%>
在下面显示
<td> <div align= "left "> <%=aa%> </div> </td>

aa是固定的几个值还是不固定的?

1,固定的几个值
if (aa.equal( "x ")){
out.print( " <font color=red> "+xx+ " </font> ");
}

if (aa.equal( "y ")){
out.print( " <font color=green> "+xx+ " </font> ");
}
...........

2,不固定的

循环外设变量tempXX= " ",tempColor= "red ";

循环内
if (xx.equal(temp)){
}else{
if ( "green ".equal(tempColor)){
tempColor = "red ";
}else{
tempColor = "green ";
}
}
out.print( " <font color= "+tempColor+ "> "+xx+ " </font> ");
temp =xx;