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