Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Context problem

 
Adrien Ruffie
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have a problem and I don't know the best way to do that.

The context: I have a webapp where I save, delete, update "server" and "user" from my webapp
in a file under /WEB-INF/classes/datafile.xml

Imagine I log me on the webapp as "administrator/administrator" (login/password), after that I
modify server informations then the webapp rewrite my datafile.xml under /classes in order to
update the modified informations for one server.

But when the datafile.xml is rewritten the web server reload the context and when the
web application being reloaded, all sessions are delete so requiring users to identify themselves again.

Anyone know the best practice for this case ?

I have found session-time out parameter in web.xml, but in this case it isn't a timeout ...

I have also found this "reloadable" attributes in tomcat configuration:

<Context docBase="myapp-ui" path="/myapp-ui" reloadable="true" source="org.eclipse.jst.j2ee.server:myapp-ui" debug="0">
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a reason you're writing to the "classes" folder? I suspect the reason it's reloading everything is because it's seeing a change to that folder.

Typically, if I have to write data to a local file, I either use a "WEB-INF/data" folder, or a folder completely outside of my webapp.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete is giving you good advice. Never write to the /classes folder. In fact, it's best to not write anywhere in the web app at all. Follow the advice of writing somewhere outside the app. That way, you don;t need to worry about what happens to the files when you redeploy the app.
 
Adrien Ruffie
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response, but can I write for example under /WEB-INF/data and not in /WEB-INF/classes without the application doesn't reload ?

Because you suggestion to write outside app for example in /home/myuser require to be configured when the application deployment, but unfortunately

I shouldn't have to make deployment configuration for my product ...


Thank you again,

Adrien
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adrien Ruffie wrote:Thank you for your response, but can I write for example under /WEB-INF/data and not in /WEB-INF/classes without the application doesn't reload ?

Yes.

Because you suggestion to write outside app for example in /home/myuser require to be configured when the application deployment, but unfortunately

No. The whole point of writing outside the web app is that the file isn't configured as part of the web app. That way, it doesn't get in the way of, or get trounced by, future deployments.

You'd serve the file via a servlet that reads and streams the file from its external location.
 
Adrien Ruffie
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Bear Bibeault,

I take the first solution to write under /WEB-INF/data for example
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic