Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Differentiating between two browser clients for JSP application

Thread view: 
Exceedingly - 09 Feb 2006 01:27 GMT
I have a JSP application that I would like to modify. This application
consists of an index page, a configuration page and a data page:
    index.jsp    - just a list of links - one for each of the following
pages
    config.jsp    - forms for setting colors, fonts, etc. and a "Save"
button
    data.jsp    - full set of data with scroll-bar

The config.jsp page allows the user to select a variety of settings
which are saved-to (and read-from) a server-side configuration file
(my.config) - so that when the application is re-launched the
previous user settings can be reasserted. These user selections are
applied to the look of the data pages.

Currently there is only one browser client accessing these pages. But a
second browser now needs to access these pages. This second browser
needs to have its own configuration settings (and related my.config
file) so that it can have its own look for its data pages. In other
words, each browser client wants to have its own set of configuration
settings and data-page look.

My question is this: What is the best way to keep track of which
browser is accessing the pages so that the correct configuration
settings can be used/retained (my1.config and my2.config or such)? I
need to know not only the best approach but the details of how to
implement it. This is an intranet application and as such I have full
control over the browser and server sides.

I need some way to provide an identifier to the application telling it
(the application) which browser is accessing the page. I am aware that
a parameter can be passed to a JSP page via the URL (although I would
need to know the details of implementing it). But is that the best way?
What about cookies (I don't know the details of implementing this
either)? Any other ideas?

Here are some further details:

- config.jsp is tied to Config.java which has the getters/setters for
each user-selectable setting as well as the read/write methods for the
my.config file.
     <jsp:useBean id="myConfig" class="server.config.Config"
scope="application" />

- When any of the JSP pages are accessed the application looks for an
existing my.config file and, if found, reads it and sets the user
settings to reflect the contents of my.config. If the file does not
exist the user settings are set to predetermined defaults.
     The JSP-Page:
           <jsp:setProperty name="myConfig" property="filepath"
                                     value="<%=
application.getRealPath("/WEB-INF") %>" />
     The Corresponding Config.java methods:
           public void setFilepath(String filepath) {
                 this.filepath = filepath;
                 if(!loaded) {
                       load();
                 } else {
                       Log.log("Not loading settings because they are
already loaded);
                 }
           }

           public boolean load() {
                 setDefaults();
                 boolean result = true;
                 try {
                       String fullpath = filepath + File.separator +
filename;
                       input = new FileInputStream(fullpath);
                       settings.load(input);
                       loaded = true;
                       input.close();
                       input = null;
                 } catch(IOException ioe) {
                       Log.log("Error loading settings: " + ioe, ioe);
                       result = false;
                 }
                 return result;
           }

- When any of the pages are accessed the Config class is utilized to
provide that page with its required user-selected settings.
     <jsp:useBean id="myConfig" class="server.config.Config"
scope="application" />
     <jsp:useBean id="myData" class="server.data.MyData"
scope="application" />
     myData.setSortOrder(myConfig.getSortOrder());        // typical

- When the "Save" button is clicked on the config.jsp page, the
Config class is utilized to save the settings to the my.config file:
     The JSP-Page:
           <%
                 if(request.getParameter("SaveButton") != null) {
                        myConfig.save();
                 }
           %>

     The Corresponding Config.java methods:
           public boolean save() {
                 boolean result = true;
                 try {
                       String fullpath = filepath + File.separator +
filename;
                       output = new FileOutputStream(fullpath);
                       settings.store(output, "Video Wall Settings -
Generated File!");
                       output.close();
                       output = null;
                 } catch(IOException ioe) {
                       result = false;
                       Log.log("Error saving config file", ioe);
                 }
                 return result;
           }

Any tips, documentation or examples you can direct me toward would be
appreciated. Thanks!!
wadi - 11 Feb 2006 13:14 GMT
Might be cookies may be a solution.
Exceedingly - 21 Feb 2006 22:40 GMT
Can you tell me how to use cookies for this purpose - or point me to
some info?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.