这是我的代码,
<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++;
}
%>
我想以表格格式打印结果。我使用了表排序器,但是它以表格格式显示了标题,但是如何在此表中打印csv的详细信息?
最佳答案
<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>
尝试上面的代码。