Dear friends

I am beginner to jsp ...I want to upload files to server .. I am using the the following code.

saveFile = "C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\\ROOT \\Extrusions\\" + saveFile;
FileOutputStream fileOut = new FileOutputStream(saveFile);

Now i want to save the file into my server ..what should i give to save file . pls help me ...


6 Years
Discussion Span
Last Post by ~s.o.s~

Hey man,

You posted this in the wrong forum (sure JSP is Java still though). But go to the forum under "Web Development > JSP", you'll get your answers there faster.



I don't think saving files in a deployment directory would be a good idea. Two solutions come to mind:

  • Use a persistent storage solution like a database (e.g. SQLite) or some other NoSQL solution like Cassandra
  • If you want to go for a simpler file system based solution, read the STORAGE_PATH system property (specified by -D switch when starting the JVM) in the ServletContextListener, store it in the ServletContext and whenever you want to store a file (for e.g. in your servlet), just do:
final String storagePath =
  new File(context.getAttribute("STORAGE_PATH").toString());
final String file = new File(storagePath, 'song.mp3');
// write to file and it will be saved to the path denoted by the
// STORAGE_PATH system property

Edited by ~s.o.s~: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.