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 ...

Thanks
Anand

Recommended Answers

All 2 Replies

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.

Cheers,

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.