• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

problem in file upload with struts 2?

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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



File name:null

can anyone suggest me, what is the problem?

Thank you in advance.

Ranch Hand
Posts: 300
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.




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.

Ritesh Dwa
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jatan.

After changing the configuration, it worked.

Again thanks a lot.

The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic