views:

119

answers:

7

Hi,

I've developed a j2ee application, now say sample.war is the file. When we port this to tomat webapps, it explodes to sample folder. But if we want to run this application for two people, how do we do that? some thing like http://address.com/user1/ and http://address.com/user2/ and in this we have different CSS (only the look varies)

Or can we take two subdomains, and link to the same application? with different styels.

Regards

+1  A: 

Possible solutions:

  1. In the deployment descriptor (web.xml) you can set the deployment target name (default is the .war name).

  2. Rename the .war (user1.war user2.war) and deploy it two times.

Take care of your connections (database / files ...) wich are used by the applications.

Martin K.
There are a lot of different solutions! You can use URL rewriting to take care of subdomains. After deployment, the application can be used by both clients. Does they use the same database connection? What kind of application do you deploy and what kind of data is processed? Maybe you have to do much more to provide multi-client functionality. You can handle URLs much more easy (see JEE starndard.)
Martin K.
A: 

Since a context is just a path under the webapps folder, you can just explode your war, then construct symbolic links for each instance you want to create, substituting different css files as needed. Two copies will also work, but you will need to modify different instances, which may be difficult if you have many instances to edit.

futureelite7
If symbolic links are working depends on the platform and application server implementation
Martin K.
I've tested it to work on centos5 / tomcat with a bit of configuration.
futureelite7
A: 

That wouldn't scale well to 100s and 1000s of users.

The general idea is that your pages have some level of dynamic capability. Read up on JSPs as one possible apporach. Bits of the HTML are generated at runtime, and one such bit could be the selection of a particular stylesheet based on teh user's id, or preferences retrieved from a db.

djna
A: 

If styles are your only change for each user, I'd recommend looking at the way Spring handles skins in its web MVC layer. Either use Spring or design something like it to accomplish this. You'd use a filter or controller to reroute users to URLs that would use different CSS files.

duffymo
A: 

If really you want to deploy the same application twice on two "context path" (not sure what you mean by two people but this is what you are showing in your sample URLs) but with different L&F, simply package and deploy two wars with their own set of CSS i.e. sample1.war and sample2.war. I can think of perfectly valid reasons to decide to do this (separate resources management like db pool, QoS, etc).

If you are using a Apache HTTPD as front-end, you could also create two virtual hosts (for example for the subdomains user1.example.com and user2.example.com), forward the dynamic requests (JSP and servlets) to Apache Tomcat and put the static files (including the CSS) at the virtual hosts level. Whether you map your vhosts on one or two webapps really depends on your needs. As I said above, there are valid use cases for deploying a war twice.

Another option would be to use mod_rewrite to play with URLs and then have your webapp dynamically pick the desired CSS.

Personally, I tend to prefer using a web server as front-end to serve static files because a web server is just better suited than a servlet container for this job (servlet containers have been improved in this area though). But this makes obviously the architecture and deployment process a bit more complex.

Pascal Thivent
+1  A: 

You can just put your webapp in context root with <Context path="/"> and pick the style based on the logged-in user or on pathinfo something like as <link href="${user.name}.css">.

BalusC