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

Problem after uploading microsoft excel (.xls) file using struts

 
Krish
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Iam facing a problem with uploding .xls files using struts.iam able to upload .txt,.doc,.csv files.If i try to upload .xls files there are uploading to the loacl drive say for eg.C or D drive.If i try to open the
file from the drive location(C or D), iam not able to view the content.

my code for upload is,

**** htFileList is a HashTable which contains the files to be uploaded.
**** path is a sting array which contains the paths where the files will
be uploaded.

**** I used MultipartRequestHandler for storing the file sin HashTable.

Added UBB code tags for readability
[ October 27, 2006: Message edited by: Merrill Higginson ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've uploaded many an .xls file using the Struts upload function and have not had this problem. The obvious suspect is the code you're using to create the Hashtable of FormFiles. I'd suggest you try an experiment to see if this is the case or not.

Code up a simple JSP that uploads a single file, and code a simple ActionForm to go along with the page that has a single FormFile property. Then just let Struts populate the FormFile normally and use similar code to what you posted above to write the file to disk. If this file is readable and the others are not, then you know the problem is in your code that creates the HashTable.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is with your choice of BufferedWriter. This class is used for text files. For binary files you will want to use BufferedOutputStream. Also, you should move the opening and closing of your output file outside of the loop so you don't have to do this for every byte that you read from the input stream.

- Brent
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI, I got a private message from Aswinle saying that the following code worked:

BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(pathinfo+"\\"+htFilesList.get("file"+(fileCount)), true));

Cool! I am sure I am not the only one that thinks that the java.io package is a bit confusing. It always seems like there is 10 different ways to do everything. The "InputStream/OutputStream" versus "Reader/Writer" naming convention seems like a bad design decision.

- Brent
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic