简体   繁体   中英

how can i add an incrementing id to the jsp page

i have four values filedata,filename,username,filestatus fetched from database but their is no id in the database,and i cant change the database,but need to add the id to jsp page

for(id=1;id<=20;id++){
System.out.println(id);
}

 %>
<tr>
<td><%=id %></td>
<td><%=filedate%></td>
<td><%=filename%></td>
<td><%=username%></td>
<td><%=filestatus%></td>
</tr>
<%
}
}
catch(SQLException ex){
System.out.println("exception--"+ex);

}

this is my code i tried giving an for loop but does not work

Your should not put your own loop , instead u might have upper loop for result set / collection object for db records. So , increment a variable within loop and use that variable as a ID. If you are doing POC just do it in Scriptlet

<% int id = 1 ; %>
<% for(Files file : files) { %>

  <tr>
    <td><%=id %></td>
    <td><%=file.filedate%></td>
    <td><%=file.filename%></td>
    <td><%=file.username%></td>
    <td><%=file.filestatus%></td>
  </tr>
<% 
id++;
} %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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