I have a similar requirement. Did you find a way to do this? It doesn’t look like you ever got a response.
We cheat and use jspSmartUpload that handles all that file upload stuff. You can get it from http://www.jspsmart.com. It takes care of everything, and we don't have to worry about where the file actually manifests itself. We've been using for a couple of years now in a variety of environments - standalone, embedded, Jetty/Tomcat.
With the smartupload facilities, you can save it to a physical context easily. You would need to create this physical context, but I'm not sure how you would do it otherwise. For example, create an upload context (unless you have security issues). Your other option is to deploy an unpacked WAR.
We tend to store these things in a database (not hsqldb) and smartupload helps in this case. You can then build a display servlet fairly quickly. However, it depends on your access/retrieval requirements.
Thanks for your reply,
I have the upload part figured out. I just drop the file in a temp directory on the server from my request controller and pass the location and original name on to the handler for the form. The handler moves the file wherever it needs it and adds data to the database about it. Since people have to find these files to work with them, and there are a lot of them, keeping them organized is a big requirement.
The part that has got me stumped is displaying them so users can see what they have. Since I can’t just point to the file (packed WAR), and security is an issue, maybe I can read the file from the jsp page and write the data out using the writer. Does this sound reasonable? How do I tell the browser what format the data is in (gif, jpg, etc.)?
You can do that, although we do it with a servlet and our source is the DB. File display may be a little slower, and depending on load may not be suitable. You probably need to trial it and see.
You tell the browser via the content type setting. You'd probably need to detect the file extension. We do it this way in our servlet (modified for bits you are going to do as we don't actually deal with files):
private HashMap hash = null;
* Init the servlet
final public void init(ServletConfig config) throws ServletException
hash = new HashMap();
// Add other appropriate mapping for bin types
public final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
String filename = request.getParameter("filename");
ServletOutputStream out = response.getOutputStream();
// Implement get file and extension
if (file exists) <-- appropriate test
// Do something appropriate to do generate
// browser friendly (maybe error gif)
if (data.length > 0)
out.println("" + e.toString());
So if this servlet is mapped as /Image
You would have in a calling page:
You'd need to have some way of knowing what the name of the picture is the user uploaded.
Another of the reasons we use JDBC storage is that we can map user to image and not have other users access the picture and users don't overwrite the picture of another user. Smartupload also makes sure there are no clashes when the files are uploaded and temporarily materialised.
Hmm, giving away all our commercial secrets.
This is the part that I couldn't quite put together. Thank you. I will let you know how it goes!