Results 1 to 4 of 4
- 09-19-2012, 07:38 AM #1
Member
- Join Date
- Sep 2012
- Location
- Kathmandu
- Posts
- 2
- Rep Power
- 0
Struts2, problem with file upload?
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
Java Code:...... <s:form action="processUpload" method="post" namespace="/" enctype="multipart/form-data"> <s:file name="upload" label="Upload File"></s:file> <s:submit label="Submit" /> </s:form> .....
struts.xml
Java Code:...... <action name="processUpload" class="action.ProcessUploadAction"> <interceptor-ref name="basicStack" /> <interceptor-ref name="fileUpload"> <param name="allowedTypes">application/ms-excel,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</param> </interceptor-ref> <result name="input">upload.jsp</result> <result name="success">upload.jsp</result> <result name="error">upload.jsp</result> </action> ......
ProcessUploadAction.java
Java Code:.... private File upload; private String uploadContentType; private String uploadFileName; public void setUpload(File upload) { this.upload = upload; } public void setUploadContentType(String uploadContentType) { this.uploadContentType = uploadContentType; } public void setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; } public String execute() { try{ System.out.println("File name:"+upload); }catch(Exception ex){ ex.printStackTrace(); } return SUCCESS; } ....
Output:
File name:null
java.lang.NullPointerException
can anyone suggest me, what is the problem?
Thank you in advance.
- 09-19-2012, 10:13 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Struts2, problem with file upload?
What does the file upload interceptor do?
What happens if you remove it from the stack?
Indeed, I'd pare this right back to simply trying to upload the file, then start adding bits in to see what breaks.Please do not ask for code as refusal often offends.
- 09-19-2012, 12:39 PM #3
Member
- Join Date
- Sep 2012
- Location
- Kathmandu
- Posts
- 2
- Rep Power
- 0
Re: Struts2, problem with file upload?
it worked, after changing configuration at struts.xml. I used default stack in interceptor.
- 09-19-2012, 12:51 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Facing Problem to upload Struts2 Based Web App
By shahinengg in forum StrutsReplies: 11Last Post: 01-13-2012, 09:37 AM -
problem with file upload
By i4ani in forum Java ServletReplies: 10Last Post: 10-21-2010, 12:44 PM -
:large file upload to server(chunk upload)
By tommy_725 in forum NetworkingReplies: 0Last Post: 10-16-2009, 12:21 AM -
Struts2 :File upload and div on same form
By saqib in forum Web FrameworksReplies: 2Last Post: 08-19-2008, 11:41 AM -
File Upload Servlet problem
By jeniramires in forum Advanced JavaReplies: 3Last Post: 08-18-2008, 07:34 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks