guys i ve a similar problem.
I know that java.util.Preferences class saves data as per user account that is executing the application. I ve a web application that uses tomcat as a web server which runs as a service. My problem is that, i want to save, each user's prefereces, that logs in to my web application.
if java.util.Preferences is not the right approach to go for my problem i would gladly like to know any ther appraoch.
> I ve a web application that uses tomcat as a web
> server which runs as a service. My problem is that,
> i want to save, each user's prefereces, that logs in
> to my web application.
The classic way for a server to save user preferences is for the server to set a "cookie" in the client/user machine. This Google search has information and tutorial listings:
http://www.google.com/search?q=java+cookie+set
If you want to maintain the preferences on the server, then Java's Preferences class is designed to do that. Here's an example:
http://www.devx.com/tips/Tip/13446
and search results:
http://www.google.com/search?num=100&hl=en&c2coff=1&q=java+save+user+preferences&spell=1
Cookies store settings on a per-machine basis. If you want to store user settings so they see their own preferred stuff whereever they log in store the preferences in some persistent storage on the server indexed on userid (and make them log in of course).
XML files work if it's not a lot, a relational database (or object database if you want to be post-modern) is better.
> Cookies store settings on a per-machine basis. If you
> want to store user settings so they see their own
> preferred stuff whereever they log in store the
> preferences in some persistent storage on the server
> indexed on userid (and make them log in of course).
> XML files work if it's not a lot, a relational
> database (or object database if you want to be
> post-modern) is better.
Windows XP Pro maintains separate cookie stores by user. I don't think that normal processes (on XP Pro) will set cookies to other than the current user, but I could be wrong, having never tried. Bottom line, there isn't a machine level cookie store in XP Pro. I didn't check other OS's.
> Windows XP Pro maintains separate cookie stores by
> user. I don't think that normal processes (on XP Pro)
> will set cookies to other than the current user, but
> I could be wrong, having never tried. Bottom line,
> there isn't a machine level cookie store in XP Pro. I
> didn't check other OS's.
true. But that doesn't represent a user on the serverside.
Many computers are used by more than one person under the same login, in which case those would all share the same options for the web application as set by the last one changing them from that terminal.
On another terminal their settings would be different.
By storing the information on the server they'd always get their own settings, not just when using their private machine but also when visiting elsewhere.
> true. But that doesn't represent a user on the
> serverside.
> Many computers are used by more than one person under
> the same login, in which case those would all share
> the same options for the web application as set by
> the last one changing them from that terminal.
> On another terminal their settings would be
> different.
>
> By storing the information on the server they'd
> always get their own settings, not just when using
> their private machine but also when visiting
> elsewhere.
If all users work under one userid on the client computer (or the server ignores the client id), then the only way your approach works is to maintain a full user database on the server with each user's id, passwords, preferences, and validation routines, and require that every user log on for each access of the server. In most cases, a single session involves multiple server accesses during a transaction, which would be impossible to handle correctly.
This is not a good approach from both the security aspect - each user should be logging on to the client machine using their own userid - and the usability aspect.
I recommend against this approach.
>
> This is not a good approach from both the security
> aspect - each user should be logging on to the client
> machine using their own userid - and the usability
> aspect.
>
It's not a bad approach at all. In a corporate environment a machine needs to be accessible to everyone using a single account. Else (and I've encountered this many times) when the main user of the machine is ill or otherwise not in the office others can't get to locally stored data (which can be required more often than you think).
Besides which, your idea of setting cookies to store all user preferences doesn't solve the problem of users logging into the application from different workstations.
In fact, it cannot solve that problem. The only thing that can (and isn't a security risk at all) is storing the information on the server.
Of course if you don't trust your own people who have access to that server you do have a problem but that problem is far bigger than where to store the preferred colour scheme for your web application on a per-user basis.