java - 使用jsp以表格格式显示csv文件数据

标签 java jsp csv

这是我的代码,

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

尝试上面的代码..

关于java - 使用jsp以表格格式显示csv文件数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28846513/

相关文章:

java - 单一职责原则与贫/富域模型有何关系?

java - 通过引用传递 HashMap

php - 如果项目已经存在,如何重写相同的mysql表行?

java - JSP - TransformerFactory.newInstance().newTransformer(xsl) 返回空值?

java - 将带有 css 的 Jsp 转换为 pdf

json - 如何在 CLI 中运行 npm 包?

python - pd.to_csv 保存,但显然是错误的数据(根据打印功能)

java - Riak:通过 Java/Scala 在键上创建索引

Java Eclipse - 简单的快捷方式

javascript - jsp中隐藏动态div