<tr><th>s.no</th>
<th>File name</th>
<th>Date and time</th>
<th>Show</th></tr>
<%
while(rs.next()){
String id=rs.getString(1);
String name=rs.getString(2);
String date=rs.getString(3);
try{
File file=new File("C:\\Users\\Ragulprasath\\Desktop\\Register\\src\\main\\webapp\\uploaded\\"+name);
if(file.exists()){
//what should put here
}
else{
//also here
}
}
catch(Exception e){}
%>
<tr>
<td><%=id%></td>
<td><%=name%></td>
<td><%=date%></td>
<td><input type="button" onClick="location.href='view.jsp?msg=<%=name%>'" value="View the contents"/></td>
</tr>
<%}
%>
我该如何根据文件是否存在(绿色)来设置行的颜色,如果不存在,则行应该是红色的。在此我正在获取文件名等详细信息并检查它是否存在但我不知道进一步进行
回答1
我真的不知道任何 JSP 但无论语言是什么,你都应该在你的 IF/ELSE 块中设置你想要的颜色(如果你在这段时间里,不要认为你真的需要 ELSE)
// ....
While (rs.next()) {
String bgColor = "#00000";
// ....
if(file.exists()){
bgColor = "#FFFF"
}
<tr style="background-color:<% bgColor %>;">
// ....