Reputation: 1
I want to upload .wav files inside Apache Tomcat server, inside Webcontent/upload
folder.
How to get path from server, so that I will put that path inside my program for uploading .wav files using Struts framework?
Upvotes: 0
Views: 1001
Reputation: 1568
For uploading file struts provide a default interceptor names fileupload
interceptor.
You just need to add this in your struts.xml
file .
like this one.
<action name="clientlogin" class="action.client.Clientaction" >
<interceptor-ref name="fileUpload">
<param name="maximumSize">2097152</param>
<param name="allowedTypes">
image/png,image/gif,image/jpeg,image/pjpeg
</param>
</interceptor-ref>
<result name ="success">/Registration/clientsuccess.jsp </result>
</action>
and in action class you can save uploaded file by this code
String filePath ="your location where you wan to save uploadedfile";
System.out.println("Server path:" + filePath);
File fileToCreate = new File(filePath, modelobj.getImagefileFileName());
FileUtils.copyFile(modelobj.getImagefile(), fileToCreate);
Upvotes: 0
Reputation: 34424
i would suggest you declare use the configuration/property file and mention the path there instead of hardcoding it in java file, then read it from there. The advantage is that even if decide to change it , you dont have to compile it again. You can just restart the server.
Just for information ,you can also use FileUpload utility provided by struts 2 as interceptor. At least have a look on this. May be you find it usefule.
Upvotes: 1