繁体   English   中英

使用JSP以表格格式显示CSV文件数据

[英]Display csv file data in tabular format using jsp

这是我的代码,

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

尝试上面的代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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