简体   繁体   中英

Display csv file data in tabular format using jsp

Here is my code,

<table cellspacing='0' class="tablesorter" >
<thead><tr>
    <th>Name</th>   <th>Description</th>  <th>Instance-id</th> <th>Region</th> <th>Public_DNS</th>
    </tr></thead><tbody>
<% 
 String fName = "c://list_win_instances.csv";
 String thisLine; 
 int count=0; 
 FileInputStream fis = new FileInputStream(fName);
 DataInputStream myInput = new DataInputStream(fis);
 int i=0; 

while ((thisLine = myInput.readLine()) != null)
{
String strar[] = thisLine.split(",");
for(int j=0;j<strar.length;j++)
 {
if(i!=0) 
 {
out.print(" " +strar[j]+ " ");
 }
else
{
out.print(" <b>" +strar[j]+ "</b> ");
}
} 
out.println("<br>");
i++;
} 
 %>

I want to print it's result in tabular format. I used table sorter but it showed heading in tabular format but how can I print details of csv in this table?

<table cellspacing='0' border="1" >
<% 
 String fName = "c://list_win_instances.csv";
 String thisLine; 
 int count=0; 
 FileInputStream fis = new FileInputStream(fName);
 DataInputStream myInput = new DataInputStream(fis);
 int i=0; 

while ((thisLine = myInput.readLine()) != null)
{
String strar[] = thisLine.split(",");
%><tr><%
for(int j=0;j<strar.length;j++)
 {
if(i!=0) 
 {
out.print("<td> " +strar[j]+ "</td> ");
 }
else
{
out.print(" <td> <b>" +strar[j]+ "</b> </td> ");
}
i++;
} 
%></tr><%
} 
 %>
</table>

Try the above code..

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