Re: How to serve two docBases under the same context path
- Original Message - From: nlif [EMAIL PROTECTED] To: users@tomcat.apache.org Sent: Thursday, October 23, 2008 4:56 PM Subject: How to serve two docBases under the same context path Hi all, I am using Tomcat 6, and I have the following problem: I am trying to separate the static content from the dynamic content of my application. In production, I intend to use Apache to serve the static content, and Tomcat to process requests to the application (mainly JSP's). This can be accomplished by writing a deployment script that will copy everything to its repsective place. My problem, however, is with the development environment: The static-content (css,js,images,html) is in one SVN project, and the dynamic (JSP,WEB-INF,classes) is in another. Thus, on my local workspace, they are on separate paths (e.g. c:\workspace\static and c:\workspace\webapp). Now, I need some way to have Tomcat serve them as a single context. I thought I'd create two context elements in my server.xml file, but they will need to have the same PATH, like this: Context docBase=workspace\static path=/myapp/ Context docBase=workspace\webapp path=/myapp/ Unfortunately, it is illegal to have two CONTEXT elements with the same PATH value. nlif, if your framework allows for this, this is what we do... Think of URLs like this a href=%=request.getContextPath()%/pathTo/myThing.htmlView My Thing/a and then it becomes fairly easy to do something like a href=%=aBean.adjustURL(request,pathTo/myThing.html)%View My Thing/a I normally use a parameter init in a servlet to set the base contexts I want. Its not unlike the filter idea mentioned which is what I think you may have to do if you cant do the above. The thing is that now we just design the web app and let TC serve the static stuff in *one* webapp. But changing a param in web.xml lets us move the static resources to anywhere, later. So adjustURL is basically saying If external context is null then use request.getContextPath else if html do this thing etc. else if jpg do that thing etc. I use a bean via an attribute which is easy to do outside of frameworks, you may find a static (thread safe) adjustURL is easier, and decide to wrap the idea up in EL or a special tag handler. I dont use tags and EL but it may be a cool thing to try... with a static class it would prbably look like a href=%=packag.name.adjustURL(request,pathTo/myThing.html)%View My Thing/a with EL something like a href=${my:adjustURL(request,pathTo/myThing.html)}View My Thing/a with tags (big guess here) something like MY:a href =/pathTo/myThing.htmlView My Thing/MY:a which could be a very cool thing if I knew how to do it ;) Hope that idea helps... TC has got all this cool powerful stuff, maybe worth giving it a try ;) --- HARBOR : http://www.kewlstuff.co.za/index.htm The most powerful application server on earth. The only real POJO Application Server. See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm --- If you cant pay in gold... get lost... http://coolharbor.100free.com/debt/usadebt.htm - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to serve two docBases under the same context path
Hi all, I am using Tomcat 6, and I have the following problem: I am trying to separate the static content from the dynamic content of my application. In production, I intend to use Apache to serve the static content, and Tomcat to process requests to the application (mainly JSP's). This can be accomplished by writing a deployment script that will copy everything to its repsective place. My problem, however, is with the development environment: The static-content (css,js,images,html) is in one SVN project, and the dynamic (JSP,WEB-INF,classes) is in another. Thus, on my local workspace, they are on separate paths (e.g. c:\workspace\static and c:\workspace\webapp). Now, I need some way to have Tomcat serve them as a single context. I thought I'd create two context elements in my server.xml file, but they will need to have the same PATH, like this: Context docBase=workspace\static path=/myapp/ Context docBase=workspace\webapp path=/myapp/ Unfortunately, it is illegal to have two CONTEXT elements with the same PATH value. -- View this message in context: http://www.nabble.com/How-to-serve-two-docBases-under-the-same-context-path-tp20132698p20132698.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to serve two docBases under the same context path
On Thu, Oct 23, 2008 at 7:56 AM, nlif [EMAIL PROTECTED] wrote: I am trying to separate the static content from the dynamic content of my application. In production, I intend to use Apache to serve the static content, and Tomcat to process requests to the application (mainly JSP's). My problem, however, is with the development environment: I'd say you should either forget about using Apache httpd altogether or make your dev environment match production. FWIW, -- Hassan Schroeder [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to serve two docBases under the same context path
From: nlif [mailto:[EMAIL PROTECTED] Subject: How to serve two docBases under the same context path In production, I intend to use Apache to serve the static content, and Tomcat to process requests to the application Why are you wasting your time, energy, and resources to do that? Tomcat is just as capable as httpd when it comes to handling static content. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to serve two docBases under the same context path
Theoretically, maybe, but in real-life heavy-duty production environments, I believe using Apache as a front to Tomcat has advantages, in areas as security, load-balancing, caching and scalability. Furthermore, the production architecture is not the issue here, as I've explained in my original post. The problem stems from the decision to separate the web-app and static-content to two projects in SVN, and this is due to the fact that different people maintain them. Thanks anyway. Caldarale, Charles R wrote: From: nlif [mailto:[EMAIL PROTECTED] Subject: How to serve two docBases under the same context path In production, I intend to use Apache to serve the static content, and Tomcat to process requests to the application Why are you wasting your time, energy, and resources to do that? Tomcat is just as capable as httpd when it comes to handling static content. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/How-to-serve-two-docBases-under-the-same-context-path-tp20132698p20135565.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to serve two docBases under the same context path
Should my dev and prod environments be identical? Really? So you deploy your source files? :-) This is one of many cases in which the development environment does not match the production environment. And as I explained in my other post, not using Apache will not change my problem. Hassan Schroeder-2 wrote: On Thu, Oct 23, 2008 at 7:56 AM, nlif [EMAIL PROTECTED] wrote: I am trying to separate the static content from the dynamic content of my application. In production, I intend to use Apache to serve the static content, and Tomcat to process requests to the application (mainly JSP's). My problem, however, is with the development environment: I'd say you should either forget about using Apache httpd altogether or make your dev environment match production. FWIW, -- Hassan Schroeder [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/How-to-serve-two-docBases-under-the-same-context-path-tp20132698p20135720.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to serve two docBases under the same context path
On Thu, Oct 23, 2008 at 9:56 AM, nlif [EMAIL PROTECTED] wrote: I am trying to separate the static content from the dynamic content of my application. In production, I intend to use Apache to serve the static content, and Tomcat to process requests to the application (mainly JSP's). This can be accomplished by writing a deployment script that will copy everything to its repsective place. My problem, however, is with the development environment: What is your development environment? Eclipse? In Eclipse, you could link the source of the static project into the dynamic project. Eclipse might even automatically combine the content in your war file. I have not tried this myself, so YMMV. You may need to write a custom ant build file to create a combined war file. You might have better luck posting on a list for your IDE. This is more of an IDE problem than a tomcat issue. -- Jeff - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to serve two docBases under the same context path
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Nlif, nlif wrote: The problem stems from the decision to separate the web-app and static-content to two projects in SVN, and this is due to the fact that different people maintain them. This shouldn't be a problem: set your Context to point to your actual Tomcat-related stuff, and set your DocumentRoot (or Alias) to the static. I don't know why you would ever need dual contexts unless you were trying to mimic your production (split Apache httpd/TC) environment by splitting your TC environment into two and trying to use two Tomcats instead. If that's what you're trying to do, it won't work. As I see it, you have several options: 1. Replicate your production environment in dev (always a good idea, as Hassan suggested) by using Apache httpd alongside TC. 2. In dev, copy everything into the same deployment directory and simply use a single context (i.e. merge these separate file sets for dev). 3. Merge your project repos back together and do either #1 or #2. Was there a particular reason to split your project in half like that in the first place? - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkkAtkYACgkQ9CaO5/Lv0PA6BwCgsg/7NOxVszEVTU+Kd4nIaLuY 8/YAni31vTqexlajwanXtRcl5t2z4wwF =mVsr -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to serve two docBases under the same context path
nlif wrote: [...] I will not, like some others (;-)), presume to guess why you want to do this. But I will presume that you have a clear way to distinguish what are links to static content from what are links to dynamic content (e.g. static ends in .html,.jpg,.css etc.. while dynamic ends in .jsp etc). With that premise, I can think of two ways : 1) as others said, set up an Apache on your development environment and do what you would do on your production one. (JkMount and JkUnmount e.g.) 2) use a servlet filter in Tomcat like urlrewrite to catch either the links to dynamic content or the others, and rewrite these links to point to the other context. See http://tuckey.org/urlrewrite/ and look at rules like rule from/allcontext/([^.]+\.(jpg|html|css))$/from to type=redirect/staticcontext/$1/to /rule - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to serve two docBases under the same context path
On Thu, Oct 23, 2008 at 10:23 AM, nlif [EMAIL PROTECTED] wrote: Should my dev and prod environments be identical? Really? So you deploy your source files? :-) This is one of many cases in which the development environment does not match the production environment. Well, deploying source files isn't exactly the same as having your development infrastructure reflect, at least reasonably closely, that of production. Personally I wouldn't work very long at a place that took such a haphazard approach. YMMV, but I'm not the one wasting time trying to work around this easily fixable discrepancy :-) -- Hassan Schroeder [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]