I am working in a J2ee application using Spring MVC framework and Hibernate with websphere application server. I am trying to develop a upload module where user can select a tab delimited text file from his machine and upload data from it into oracle 10g database (our backend). So the user should select the file, the file-type (a drop down menu) and click upload and the data should be in the database. The tab-delimited text file is nothing but excel spreadsheet tables (with first row as header). I have matching columns in the database for each column in the text file. (Note: I have seen the Apache POI framework but want to avoid it, as some of files are coming as text and some as .xsl, so I am converting everything into .txt).
Is there anything in Spring framework that will help me in this. Or else, I am thinking of using simple java IO and use regular expression to extract the data and pump it into hibernate to save it in persistant storage. The other option is perl, but how do I invoke a perl script in websphere app server. A small sample routine will be very helpful whatever the best way to do this.....
You can assume that my text file looks like this:
ColHdr1 ColdHdr2 ColHdr3 ColHdr4 -----> column header
qwe bbbbb qqwjxjx bhjuytg ------> row #1 data
dgt aghui kjiu kiyrcd ........
qwsju kiuyt juht juyt ........
> But then where do I specify the path on the server where the file will
> be uploaded? What will my upload form submit to?
You specify it in your source code, in the object where you actually do the upload. Here is some sample code: http://www.servlets.com/jservlet2/examples/ch04/UploadTest.java using the O'Reilly package.
If you go with CommonsMultipartResolver have a look here: http://www.up.ac.za/services/it/intranet/sysops/docs/spring/SpringReference.htm#mvc-multipart for information on how you can do it (source code, HTML code and any XML specific code).
> <form name="UploadForm onSubmit="??????"> . Can u pls show me (pseudocode)
> what will I have on the jsp and what will i have on the servlet? Just
> the relevant portion.....
In the HTML form you need to do something like this:
<form method="post" action="http://www.myserver.com/myservlet" enctype="multipart/form-da
<input type="file" name="myfilename"/>
<input type="text" name="anothervariable"/>
<input type="submit"/>
</form>
For uploading the file(s) you need the following bit of code (from O'Reilly)
while (files.hasMoreElements()) {
String name = (String)files.nextElement(
String filename = multi.getFilesystemName(na
String original = multi.getOriginalFileName(
String type = multi.getContentType(name)
File f = multi.getFile(name);
out.println();
}
and to save a file on the disk you can do:
MultipartRequest multi =
new MultipartRequest(req, "/tmp", 50 *1024 * 1024,
new com.oreilly.servlet.multip
You only have to change the "/tmp" folder to the one you want to save the files to.