gpt4 book ai didi

java - 在jsp中写出表格时计算总数

转载 作者:行者123 更新时间:2023-11-29 09:16:38 25 4
gpt4 key购买 nike

我正在创建一个 jsp 页面,我在其中读取一个文本文件,然后以表格格式显示该数据。现在我需要计算总数。

我正在使用 BufferedReader 读取文件,然后像这样写输出:

 String fileName = "C:\\M2011001582.TXT";
BufferedReader is = new BufferedReader(new FileReader(fileName));
int lineCount=1;
String fileData = "";
out.println("<table border=\"1\" ><thead>"
+ "<tr><th> SNO </th>"
+ "<th> Batch Number </th>"
+ "<th> amount </th>"...</tr>);
while((fileData = is.readLine()) != null)
{
out.println( "<tr>"
+ "<td>" + lineCount++ + "</td>"
+ "<td>" + fileData.substring(0,6) + "</td>" //batch no
+ "<td>" + fileData.substring(6,14) + "</td></tr>" ); //amount...
}

输出显示 4 行和 2 列。如何计算总金额?

最佳答案

将 java 代码放在服务中并从 Controller 调用此服务,只需将计算的数据传递给 View (jsp) 进行渲染

参见示例 here

关于java - 在jsp中写出表格时计算总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9014417/

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