I am creating one jsp page in which I read in a text file, then display that data in tabular format. Now I need to calculate a total.
I am reading the file using BufferedReader, then writing the output like this:
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...
}
The output displays 4 rows and 2 columns. How can I calculate the total amount?
Put the java code in service and call this service from Controller and just pass calculated data to view (jsp) to render
See the example here