0

I am working on struts2 application. I have following in my jsp (say main.jsp) –

<s:file name="sampleDocument"/>
<s:submit action="uploadSample" value="Upload" />

See here how my struts.xml handling the action -

<action name=" uploadSample " class=" UploadFiles">                 
        <result name="success"> /main.jsp</result>
        <result name="input"> /error.jsp</result>
</action> 

Its all running well. As required file is uploading. But as you have seen I am calling same jsp page (i.e main.jsp) on SUCCESS. Its coming but <s:file> textbox in empty. I mean its there is no file name that I have browse before uploading. Can anyone know how to get this?

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
vivmal
  • 317
  • 5
  • 14
  • 30

3 Answers3

0

The value of the <input type="file"/> element is cleared by default for security reasons.

See How to set a value to a file input in HTML?

Community
  • 1
  • 1
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
0

You need properties on your action that reflect the names of the parameters in your JSP. Have a look at this documentation for an explanation of which properties to look for.

Peter Kelley
  • 2,350
  • 8
  • 26
  • 46
0

you should define getter and setter functions for fileName. This will ensure that the value is populated in the view once it returns from the action.