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

extracting data using JSP

 
Sri Sar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have created an HTML form where the user is allowed to choose a text file containing data from a set of text files.
the code is below:
<select name="sel" onchange="loadFile();">
<option> choose any of the text files below and click 'Back'
<option value="D:\My Documents\ke.txt"> area
<option value="D:\My Documents\ker.txt" > population
</select>

now i want to create a JSP program on the server side that extracts the user's selections (ie the JSP should extract only the file chosen by the user) and performs the necessary processing. for example the JSP code should extract the data from the text file chosen by the user (say the user has chosen ke.txt) and perform operations like multiplying the values in ke.txt by some number etc . how can it be done.
i am a newbie to JSP and desperately need ur help in doing the above. thanks in advance.
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'd place all the file IO logic inside a JavaBean, and use the JSP page to present the results. Certainly you can place the logic in the JSP page if you'd like, and it may be easier to implement this way if you're not comfortable with Beans. So, for instance, if I'm supplied the filename from the user, I can do something like this in my JSP:

The file IO code is the same as if you were implementing it in a normal class. All you really need to know is how to get the input from the user (from the form on the previous page), and how to display your results.
For instance, if your store your results as an array of integers, you can include the following code in your JSP, after you've completed processing the file:

Hope this gives you some direction.
WS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic