Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calculations using JSP

 
Yell Srik
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i am new to JSP and need ur help in doing the following.
i have a text file that contains three columns: name, salary, tax with 10 rows of data.
eg: name salary tax
aa 1000 100
bb 2000 200
............
using JSP/Servlets, how is it possible to extract data values from salary and tax columns and perform calculation like (salary-tax),(salary+tax) etc.
thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried? What has you stumped?
 
Nadeem Ahmad
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You read the file by using
File f = new File("c:\\io\\data.txt");
RandomAccessFile rf = new RandomAccessFile(f,"rw");
rf.readLine())
and then split the line with Space or any other delimeter (which is being used in the text file)
using StringTokenizer
Here is the example..
| is the delimeter incase of ur file it is space
String username=null;
try{
File f = new File("c:\\io\\data.txt");
RandomAccessFile rf = new RandomAccessFile(f,"rw");
while((username=rf.readLine())!=null){
i=0;
StringTokenizer st = new StringTokenizer(username,"|");
String pr="";
while (st.hasMoreTokens()) {
entry[i]=st.nextToken();
i++;
}
}

}
rf.close();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic