I am able to upload files in struts2 (2.1.6) only when I remove the spring
security filter in web.xml. When I use the spring security filter, I get a
null object in File inside action class. That is the line
"testFile.length()" in sample code provided below, throws null-pointer
exception.

I am using spring 2.5.6 and Spring security 2.0.5. This worked fine with
Struts 2.0.10 and some older version of spring security (don't remember!).

Can anybody please help on this?

1. Web XML

<!--<filter>
<filter-name>
springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

-->

<!--
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->


2. Struts XML

<!--All packages extend base package-->
<package name="base" extends="struts-default">
<interceptors>
       <interceptor-stack name="base-stack">
               <interceptor-ref name="defaultStack" />
               <interceptor-ref name="fileUpload">
                       10240
               </interceptor-ref>
       </interceptor-stack>
</interceptors>
<default-interceptor-ref name="base-stack" />
</package>



3. JSP

<s:form action="save" method="post" enctype="multipart/form-data">
<s:file name="testFile" id="testFile"></s:file>
<s:submit></s:submit>
</s:form>


4. Action
private File testFile;

public File getTestFile() {
       return testFile;
}

public void setTestFile(File testFile) {
       this.testFile = testFile;
}

public String save(){
       byte[] testFileContent = new byte[(int) testFile.length()];
       new FileInputStream(testFile).read(testFileContent);

       //write testFileContent  to a local file
       writeFile("D:\\etl.gif",testFileContent);
       return ActionSupport.SUCCESS;
}
-- 
View this message in context: 
http://www.nabble.com/Unable-to-upload-files-with-in-Struts2-with-Spring-Security-filter-tp25652380p25652380.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to