To which folder should I store the files, that a user should be able to bro

I’m making a Task Manager Vaadin application in a school project. In this project, for simplicity’s sake I’m not using a database but simple xml files instead to store and retrieve data (in this case tables that have tasks as rows and task properties as columns). I’ve already managed to open xml-files to fill the tables in my task manager app. I’ve also managed to save the current table contents as xml-files to my computer.
However, I want my Vaadin application to be able to create xml-files to a specified location on the server. So, that all the files would be stored on the server and not on user’s hard disk.
I’m a complete greenhorn on TomCat, or servers in general. I noticed that I can’t save stuff on WEB-INF folder for example.

So, where can I “save” the table contents as a xml-file to, so that the user can see the stored xml-files each time he uses the application. This is just for demoing it in class, so security etc. is not an issue.

Thank you.

Hello Vesa,

I don’t have a direct answer on this, but if you have to go into making a new solution for this (if it proves impossible to use XML), you might want to look into JPAContainers. It was not a hardship to install the h2 database, and connecting to it is rather easy.

https://vaadin.com/book/-/page/jpacontainer.html
JPAContainer acts like any other Vaadin container mostly, hence this container chapter will be useful:
https://vaadin.com/book/-/page/datamodel.container.html

The easiest way to implement JPAContainer to a Vaadin project is by creating the project from a maven archetype
https://vaadin.com/book/-/page/jpacontainer.installation.html

This took little over 10 minutes to install.

What I usually do if I have a small project and just want to have a file based data store is use something like HSQLDB (http://hsqldb.org) as a database and then point that database to a file using the
jdbc:hsqldb:file:
property. Then you can use that as a normal database with JPA or whatever you want.

Hi vesa,

if you want to write into your tomcat deployment folder you can use

servletContext().getRealPath("/"); to access it. You should be careful because this folder does clear completly after you redeploy your application. But this could be the behavior you want in your case :slight_smile:

To access the servlet context you could use the VaadinRequest object in your init() mehtod

((HttpSession)request.getWrappedSession()).getServletContext() Sorry I didn’t try this out :slight_smile:

What when you don’t unpack wars in the Tomcat? Will it work if the folder does not exist in fact?

Thanks for the equally good suggestions for this case. HSQLDV seems definitely like something I’d use in the future.