tags:

views:

964

answers:

1

Hi All, In my struts2 application I am using “File Upload Interceptor”. Its running well but after uploading when same jsp page appears it does not show browsed file name in the textbox of <s:file> tag i.e textbox comes empty after successful uploading. Here is my code snippet-

main.jsp

<s:form action="smAction" enctype="multipart/form-data" theme="simple">
<s:file name="sample"/>
<s:submit action="uploadSample" value="All upload" />
</s:form>

struts.xml

<action name=" uploadSample " class=" UploadMySample">
<interceptor-ref name="defaultStack"/>
<result name="input"> /login.jsp</result>
<result name="success">/main.jsp</result>
</action>

UploadMySample.java

public class UploadMySample extends ActionSupport {            
  private File sample;
  private String sampleContentType;
  private String sampleFileName;

  public File getSample () {
      return sample; 
  }
  public void setSample (File sample) {
      this. sample = sample;
  }
//---- here file uploading code ---//

return SUCCESS;

}

Please suggest.

A: 

This is not a problem of Struts. For security reasons modern browser don't allow to set a value for file upload fields. If you want to display the file name after the upload you'll have to use simple text.

kiwi74