gpt4 book ai didi

javascript - CSV 到 HTML 表格

转载 作者:行者123 更新时间:2023-11-28 01:14:07 24 4
gpt4 key购买 nike

我无法将 CSV 文件显示为 HTML。如何使用循环将 csv 文件中的下一行变成 HTML 表中的另一行?我对这个 jsp 还是个新手...请给我一些让它工作的想法。

<body>
<%
String fName = "F:\\web\\Sales.csv";
String thisLine;
int count=0;
FileInputStream fis = new FileInputStream(fName);
DataInputStream myInput = new DataInputStream(fis);

%>
<table>
<%
out.print("<table border = 1><thead><tr><th>Customer</th><th>Customer Type</th><th>Purchase</th></tr></thead><tbody‌>");
while ((thisLine = myInput.readLine()) != null){
String strar[] = thisLine.split(";");
for(int j=0;j<strar.length;j++){
out.print("<td>" +strar[j]+ "</td>");
}
out.println("\n");
}
%>
</table>
</body>

最佳答案

问:难道你还需要打印<tr>吗?在每个新行之前,和 </tr>之后?

还有:

  1. 你有太多了<table>元素 - 删除第一个。

  2. 我不认为<tbody>是必要的......但如果你有它,你应该用</tbody>关闭它.

建议的更改(我实际上还没有尝试过...):

  <body>
<table border = 1>
<tr><th>Customer</th><th>Customer Type</th><th>Purchase</th></tr>
<%
String fName = "F:\\web\\Sales.csv";
String thisLine;
int count=0;
FileInputStream fis = new FileInputStream(fName);
DataInputStream myInput = new DataInputStream(fis);

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

关于javascript - CSV 到 HTML 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36440394/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com