Using Tomcat and Struts 2.
public FileAction class
{
......
public upload()
{
.....
String fullFileName = request.getContextPath() + "/productImages/" + filename;
File theFile = new File(fullFileName);
FileUtils.copyFile(upload, theFile);
.....
}
}
The problem is when I upload an image it will not add image in localhost:8085/shoppingCart/productImages and also not give any exception.
But when i write String fullFileName="c:upload/productImages/" + filename; it will save the file at c:upload/productImages/ path
mean working normal in c:upload/productImages/ case
If you want the file uploaded to the server’s context, you need to use
ServletContext.getRealPath(...)to find the base directory of the deployed application. Note that this will not work if you’re deploying a war file. Uploaded files should go to an absolute location on the server itself.For downloading an uploaded image you’d write a stream result (since you’re using Struts 2) and use it to load and stream the uploaded file back to the client.