I have a form that allows user to select a .csv file and post it to a servlet. However I am having dificullty getting a handle on the file from the Java Servet on the server any ideas?
5 Answers
Try OpenCSV for reading and parsing CSV files. I just tried it. It is very easy and quick. It is also with commercial-friendly license. So you can use it your production code as well.
Check out this link http://opencsv.sourceforge.net/

- 3
- 3
A mistake I make myself and see other people make often is in HTML rather than you serverside. Make sure you have enctype="multipart/form-data" in your form tag.
If that's ok see this:

- 36,468
- 26
- 90
- 114
you can not open the file you upload.you need to use inputstream to parser the file.and
“Make sure you have enctype="multipart/form-data" in your form tag”
In java programming,any upload file just can use io to parser that.When you use servlet to parser the file,use request.getInputStream.

- 1,757
- 19
- 19
To Upload your csv file into the any one of the database then you have to save your file in a folder first by browse and selecting the file.then afterwords you have to read all the columns in the csv file using FileInputStream class ...
By using this code in your program FileInputStream fis=new FileInputStream(pathheader); FileOutputStream fos=new FileOutputStream(filenamehdr);
for more check here..Upload CSV file using Servlets

- 33
- 1
- 1
- 6
-
1This is soo utterly wrong. The code example on your blog only works when you run both the webbrowser and webserver at physically the same machine and when you use Internet Explorer as webbrowser. In all other cases, this will miserably fail. You should not get the file from local disk file system by the path/name sent, but you should get the file by the content in the request body. See also http://stackoverflow.com/questions/81180/how-to-get-the-file-path-from-html-input-form-in-firefox-3/3374408#3374408 – BalusC May 11 '11 at 12:44
-
Yes ..i know but i have given for the beginners only...how to do the file insertion from the system.Any how it has to be done some modifications in the application.I agree with you but as i know i have given to you... i am not saying this is the best one to upload the file . – muralidhar May 26 '11 at 12:46
-
1That's not a valid excuse. The code will never work in production environment where webbrowser and webserver runs at physically different machines. It will also never work in browsers other than MSIE, regardless of the setup. Oh, having a `static Connection` is also recipe for major trouble. – BalusC May 26 '11 at 13:04