Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about war. files and customizing apps  RSS feed

 
Eric Howell
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about visability from a .WAR file.
I have an application I am building. It's being built using Servlets/Beans/JSP's using MVC pattern for use on Tomcat.
I'ed like the user to be able to customise it (eg fonts, HTML tables etc). I thought of using a set up Servlet (via a jsp)that will enter user's specs into a JavaBean with application scope.
If I package the app in a WAR. file could the setupServlet and bean be visable if I just put it in the Tomcat directory ? or would they all have to be in the WAR.
In other words, can classes etc inside a WAR. see classes etc outside.
(I thought the user could delete the setupservlet once it had been used once)
Also, maybe there is a better way to customise an application.
Thanks in advance
Eric


[This message has been edited by Eric Howell (edited October 23, 2001).]
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should put everything inside the WAR. The J2EE specification really tries to restrict visibility to what is within the WAR. You can add classes to the classpath of the WAR file by editing its manifest if the classes are in the EAR that contains the WAR, but trying to use external classpaths is really not recommended.
Kyle
P.S. If the USER is customizing things then each user might want it different. This should be stored on the session scope probably rather than the application scope. Also, do you want the cusstomizations to last past this particular user session? If so, you should consider storing this kind of information persistently, either in a long-lived cookie or in a database table.
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Eric Howell
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kyle Brown:
You should put everything inside the WAR. The J2EE specification really tries to restrict visibility to what is within the WAR. You can add classes to the classpath of the WAR file by editing its manifest if the classes are in the EAR that contains the WAR, but trying to use external classpaths is really not recommended.
Kyle
P.S. If the USER is customizing things then each user might want it different. This should be stored on the session scope probably rather than the application scope. Also, do you want the cusstomizations to last past this particular user session? If so, you should consider storing this kind of information persistently, either in a long-lived cookie or in a database table.

Thanks Kyle
I guess everything should go in the war. When I said 'user' I meant the person setting it up on their own server eg Tomcat.
That is why I wanted the setup.class seperate, as its an only use once class. Also, this is why I wanted application scope for the JavaBean that holds all the HTML/Database variables etc
Sorry I was not more clear
Cheers Eric
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about thinking 'less fancy' and just go for a simple style sheet that they can customize. It would be packaged up with everything else, but in your administrator's guide, you could say "to alter the look and feel of your site, change this file ..."
 
Eric Howell
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Curwen:
What about thinking 'less fancy' and just go for a simple style sheet that they can customize. It would be packaged up with everything else, but in your administrator's guide, you could say "to alter the look and feel of your site, change this file ..."

The thing is that I want to make other parameters customizable and setable like database connections, different numbers of tables for various applications etc eg for that css.
But even for using a style sheet for look and feel, wouldn't the
administrator have to extract the css from a war . Can you do this?
Maybe you could expand this a bit
Cheers
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I guess not, for some of the things you mentioned.

Definately a style sheet for fonts, headings, etc.

About the WAR file and CSS being inside. At some point, that WAR file will be expanded. If your audience is the administrative user of the application, then they will be aware (or you can make them aware through your documentation) of where the CSS will be extracted to, and then they can change it.

Normally I would use web.xml for customizable settings. The admin person would be able to (within reason!) change some of these settings. For example: in my application I use web.xml to inform the application of what jdbc driver to use, what the connection URL is, and even the username and password. (I'm relying on WEB-INF/* not being browsable!). In the same application, the results of a query are displayed in a table of 'items'... the site displays rows and columns based on numbers I enter in web.xml. So if I changed the numbers in web.xml and restarted my server, I'd have 3 rows of 10, instead of 5 rows of 6.

Now a savvy admin person wouldn't mind editing this web.xml file directly... they already do that sort of thing for their Apache and Tomcat setup.

But to automate it with a nice web front-end might not be *too* problematic. You would have to (I suppose).. write a seperate "editing servlet" that did nothing but allow manipulation of the web.xml. One question that pops to mind: Is WEB-INF/* reachable through FileIO classes, from a servlet running in that particular context?

The changes in this file would be for a single instance of your application. I'm not sure if the type of customizing you want to do is possible with this.
 
Eric Howell
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your help Mike. I certainly have a few ideas to go on.As for if WEB-INF/ can be reached from a servlet, thats somethinh I'll have to play about with. If anyone has any ideas I'ed be grateful
Thanks again for all your info Mike
Cheers Eric
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Curwen:
About the WAR file and CSS being inside. At some point, that WAR file will be expanded.
Bad assumption. Not all application servers run the application off the filesystem!
If you want to change the CSS file and other files on a deployed application, you could do it by storing these files in the database. It isn't all that difficult to write a servlet that exposes the contents of one or more database tables as a virtual path on the server (e.g. /db/style.css could invoke the "db" servlet to serve the record with primary key "style.css" from the WEB_FILES table).
- Peter
 
Gerry Giese
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric,
I think I know where you're going. What I did in my setup was place a simple java Properties-compliant text file in the filesystem to store application information. I then read it in by overloading the init() method of the servlet and store it globally. I'm hoping to add a feature that will let me post a command to the servlet (authenticated, of course) that will cause it to dump it's current settings and re-run the init(), which will read in any modified settings from the text file. Here's my example file (Application.properties):
--------------[file starts]-------------
DBURL: jdbc racle:thin:@db.mycompany.com:1521:db_sid
DBUser: user
DBPassword: password
--------------[file ends]---------------
You could also store your settings in XML, .ini, .conf, or whatever. This is the most dynamic method I've found that is simple (it just uses the java.util.Properties class) to use and work with and doesn't require lots of classes or parsing.
Here's a psuedo-code snippet that uses the file above:

TADA!
 
Gerry Giese
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, I have no idea how the colon-o on the JDBC URL became a face. Sorry about that!
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gerry, it's a smiley shorthand notation.

You'll see at the bottom of the posting form, a checkbox which says "disable smilies in this post".

If you do any jdbc urls that have oracle in them, you'll want to check that. I've been caught on that many a time.
 
Eric Howell
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gerry
I now have a few ideas about how to go forward. Using a file or XML file seem the most straight forward.
My initial idea was to store info into a bean with application scope. Just out of interest, I wonder how practical this would be and if it is ever done.
Thanks again
Eric
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!