开发者

Java EE application in tomcat

开发者 https://www.devze.com 2022-12-16 13:09 出处:网络
I\'ve developed a Java EE application. Now say sample.war is the file. When we port this to Tomcat webapps, it explodes to sample folder. But if we want t开发者_如何学JAVAo run this application for

I've developed a Java EE application.

Now say sample.war is the file. When we port this to Tomcat webapps, it explodes to sample folder. But if we want t开发者_如何学JAVAo 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 styles?


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">.


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.


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.


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.


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.


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.


Found these on net, thought you might be interested.

http://www.theserverside.com/discussions/thread.tss?thread_id=31389

http://oreilly.com/pub/a/java/archive/tomcat-tips.html?page=2

http://www.mail-archive.com/users@tomcat.apache.org/msg69795.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号