Javascript CSV到HTML表
我无法将CSV文件显示为HTML。如何使用循环将csv文件中的下一行转换为HTML表中的另一行?我对这个jsp还是新手。。。请给我一些想法使它工作Javascript CSV到HTML表,javascript,html,arrays,csv,html-table,Javascript,Html,Arrays,Csv,Html Table,我无法将CSV文件显示为HTML。如何使用循环将csv文件中的下一行转换为HTML表中的另一行?我对这个jsp还是新手。。。请给我一些想法使它工作 <body> <% String fName = "F:\\web\\Sales.csv"; String thisLine; int count=0; FileInputStream f
<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>
Q:您不也需要在每一行之前打印
,在每一行之后打印
此外:
您有太多的
元素-删除第一个元素
我认为没有必要。。。但是如果您有它,您应该用
关闭它
建议的更改(我实际上没有尝试过…):
客户类型购买
谢谢你的建议!我会试试的!:)@paulsm4
<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>