wood burning stoves 2.0*
The moose likes JSP and the fly likes extracting data using JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "extracting data using JSP" Watch "extracting data using JSP" New topic

extracting data using JSP

Sri Sar
Ranch Hand

Joined: Mar 25, 2004
Posts: 44
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

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

Joined: Jun 06, 2003
Posts: 136
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.

for (int i = today; i < endOfTime; i++) { code(); }
Consider Paul's rocket mass heater.
subject: extracting data using JSP
Similar Threads
advise on using XML in the application
javascript and database
generating dynamic XML
using javascript to create XML
generating XML using servlets/jsp