我在将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>发布于 2016-04-06 10:56:22
问:您不是还需要在每个新行之前打印<tr>,并在之后打印</tr>吗?
另外:
<table>元素太多-请删除第一个元素。<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>https://stackoverflow.com/questions/36440394
复制相似问题