This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Struts and the fly likes problem in file upload with struts 2? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem in file upload with struts 2?" Watch "problem in file upload with struts 2?" New topic
Author

problem in file upload with struts 2?

Ritesh Dwa
Greenhorn

Joined: Sep 18, 2012
Posts: 7

hello,
I am using struts 2.2.1 framework with jdk 1.6 and running in tomcat 7. In my web application, I want to upload excel file and read the content of that file. I have searched many websites and even apache website as well but I could not solve my problem.

After uploading file, when I try to read the uploaded file, error occurs : java.lang.NullPointerException. I think the variable "upload" in java file, should automatically initialized after file upload. isn't it?

I think my code is good, but its not working.

upload page: upload.jsp


struts.xml


ProcessUploadAction.java


Output:
File name:null
java.lang.NullPointerException

can anyone suggest me, what is the problem?

Thank you in advance.

jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Ritesh ,

struts inteceptor remove the temp file once the file is uploaded so you need to copy files with file. Also as far as nullpointer exception is concern you need to check the configuration. I have used your code in sample application and uploaded file with minor changes.

You need to copy the uploaded file then you will be able to see it.

Jsp:


Action:


struts.xml:



It did work for me . You need to store the uploaded file in db or some location on server as struts inteceptor removes the file uploaded and you wont be able to see in your system. It gives you the info in the console like
INFO: Removing file upload E:\workspace1.5\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\struts2\upload__3c0968c2_139dd3c2d69__8000_00000001.tmp .

You can print the filename in setuploadfilename method where you can see the full path where the struts is uploading the file.

Regards
Jatan
Ritesh Dwa
Greenhorn

Joined: Sep 18, 2012
Posts: 7
Thank you Jatan.

After changing the configuration, it worked.

Again thanks a lot.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in file upload with struts 2?