|
||
The SessionWeb Programming uses the concept of a "session" to keep track of user data.When a user visits your website, he/she may visit more than one pages. Usually for user interface reasons, it is a good idea to separate data entry into several pages. But we would like to be able to connect all these pieces of data with the same user. While he/she is visiting some pages, other users may be visiting other pages using the save web server. So the problem is, how to keep track of the data for each user. The "session" concept is useful for this. A "session" is an object that is associated with a visitor. Each visitor gets his/her own session object. We can store all data related to the visitor in that session object. But that we don't know if the visitor is going to visit more pages, or has gone away to another site or has closed the browser. So sessions have a "timeout". If the user has not visited any pages within, say, 10 minutes, we assume the user has gone away and delete the session object. Sessions are provided by web-server back ends, such as Java Application Servers.
Jaxcent uses the session object to provide a Jaxcent can automatically save and restore data from forms in this Map. This data is saved by using the id or name as keys. The data stored consists of INPUT, SELECT and TEXTAREA items. You can also save your own items in this Map, as long as your keys do not collide with the form names/id.
To enable this automatic saving/restoring, the <AutoSessionData>true</AutoSessionData>This tells Jaxcent to load form items with session data when the page is loaded, and to save any changes in the session when the page is unloaded. To try this out, we will create some HTML pages with input elements on them:
tutorial" and class "Summary".
Add a constructor and write some output to System.out, to verify
that the page is connected.
Now add entries for all of these except Contents.html, in the config XML file. Note
that we only have one Java class. Use <AutoSessionData>true</AutoSessionData> Now visit all of these, entering data in the forms. Any data you enter in the forms, should be staying in those forms when you visit the form again. Even if you refresh the page or visit the URL without going back, the data will stay on the page. However, if you leave the browser for more than 10 minutes and then come back, any pages you revisit will have lost their data, because the session would have been lost. (Except that if you have left your browser on one of these pages during those 10 minutes, that page's existing data would get loaded again.) If you start another browser (not "New Window" from the same browser, but a new instance or a new type of browser, e.g. IE and Mozilla), you will not see your changes. You could enter a fresh set of data using that browser, and it will be kept track of. (Here are you acting as a second user.)
This is happening because of the Exercise:
Get all this to work and verify that it is working by visiting
http://localhost/Contents.html
in the browser. Verify that all the data sticks.
|
||
|