Home > Back-end >  In a table i have a list of files.If the file exists,the row bg color should be green or else red
In a table i have a list of files.If the file exists,the row bg color should be green or else red

Time:05-20

<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>
<%}
%>

How can i do this to set the color of the row based on whether the file exist(green) if not row should be red.In this i am getting the details like file name and checking it if it exists or not but i dont know to proceed further

CodePudding user response:

I dont really know any JSP but whatever the language is, you should just set the color you want in your IF/ELSE block (dont think you really need the ELSE if you're in the while)

// ....
While (rs.next()) {
    String bgColor = "#00000";
    // ....

    if(file.exists()){
       bgColor = "#FFFF"
    }
    <tr style="background-color:<% bgColor %>;">
// ....
  • Related