2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

trying to upload a file using struts 2 framework and doing ajax submit. but every time getting .tmp file at server side.

my problem is i am trying to upload a file which could be .txt or .jpg etc. But when i am retrieving the file at backed i am getting .tmp file everytime. I tried many way to get the actual file. Its printing the actual size of the file but at the end its giving me .tmp file. The process i am folling is as below:

in struts.xml file i configured as below:


<action name="upload" class="com.test.UploadFile">

   <interceptor-ref name="basicStack">

   <interceptor-ref name="fileUpload">

  <param name="allowedTypes">image/jpeg,image/gif etc...</param>

   </interceptor-ref>

   <result name="success">/success.jsp</result>

   <result name="error">/error.jsp</result>

</action>


and i am trying to do form submit using html tags.

Please anybody suggest what to do in that case.

userimage

This situation i already faced. Probably there would be many other solution but the solution i did really worked for me.


I put struts.xml


<action name="upload" class="com.test.UploadFile">

   <interceptor-ref name="basicStack">

   <interceptor-ref name="fileUpload">

  <param name="allowedTypes">image/jpeg,image/gif etc...</param>

   </interceptor-ref>

   <result name="success">/success.jsp</result>

   <result name="error">/error.jsp</result>

</action>


used html code like below:


<form action="upload.action" method="post" enctype="multipart/form-data">

             <input type="file" name="filename" />

             <input type="hidden" name="newname"  id="actualfilename"/>

             <input type="submit" value="Upload" onclick="abc()"/>

</form>


at form submit time i set the 'actualfilename' withe the file name uploaded by user as below:


$('#actualfilename').val(<set the file name by getting the file name using javascript.>)


and from server side the moment you will get the .tmp file just write the file with the file name you have got from client side.


Hope this will help a lot.

Answer is