Re: Aaarrrghhh!! CSS and Servlet again
> What happens it your www.site1.com decides to > deploy the application as www.site1.com/app1...? The context path is set in the > deployment descriptor, not in the code. You really should make your code > independent of the deployment descriptor even if it just happens to be that your > current deployment descriptors match your code. It is an upfront decision to go with a "root-relative" site (and site promotion process), like going with java as opposed to the many other technologies (what would happen if your site decides to use C on the backend?). It is something that needs to be agreed upon early for a large, multi-faceted site. Our sites are mostly built with XSL/XML ( perhaps 1 to 4 XSL guys working on a site at a time) and currently they are mostly separate from any backend processes (maybe 75% pregenerated to html). If I were to implement what you are talking about: (- there would need to be some way to dynamically generate the previously pre-generated pages, or - pre-generate on and with each particular machine's context, ) and - pass the approriate variable parameters to the XSL This could defeat the promotion process. Currently we are assured that what is seen on qa is what will be on live. The only variable in the promotion process between qa and live is the cost/type of machine. Since there are several resources (human and not) involved it is better to set the site structure early. It really clears things up for all invloved and allows for a clean separation from others.
Re: Aaarrrghhh!! CSS and Servlet again
The thing is, the specification you are working to defines the context path as a deployment decision. It is simply coincedence that the context path in all of your deployments is the same (root). Even in your situation, you should prefix ANY hard coded URLs with getContextPath, because that protects you. It is not a thing that ever fails, it will always work, and it will always protect you from different deployment issues. What happens it your www.site1.com decides to deploy the application as www.site1.com/app1...? The context path is set in the deployment descriptor, not in the code. You really should make your code independent of the deployment descriptor even if it just happens to be that your current deployment descriptors match your code. John H. "Robert Koberg" <[EMAIL PROTECTED]>@orionserver.com on 06/22/2001 10:21:15 AM Please respond to Orion-Interest <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] To: Orion-Interest <[EMAIL PROTECTED]> cc: Subject: Re: Aaarrrghhh!! CSS and Servlet again Hi John, I see why you are doing that but I don't agree it is a good way to go, at least for me. It looks like you are a corporate developer who builds for an intranet that would benefit from the context paths. But, for me (internet development - each site unique), it works out better for the whole team when the dev (and qa) server is setup with virtual hosts (? I am not a sys admin, so...): Dev server dev-site1.workingdomain.com dev-site2.workingdomain.com QA server qa-site1.workingdomain.com qa-site2.workingdomain.com Live server(s) www.site1.com www.site2.com This way everyone is working (and qa'ing) out of the same environment as it will be when live. As for my personal development, I do work on local machines at home (not the dev box) whenever possible. We keep everything in sync with CVS. I also have the 5 static IPs and keep a machine/static IP for each project. It is easier for me (and everyone else on the team) to work without the context path. I do see the context path as a problem in these containers especially when working on large projects/groups with a variety of skills and needs. I feel it is better to keep the same environment through the site promotion process. of course there are other ways to do it... Thanks for the discussion, Rob - Original Message - From: <[EMAIL PROTECTED]> To: "Orion-Interest" <[EMAIL PROTECTED]> Sent: Thursday, June 21, 2001 3:34 PM Subject: Re: Aaarrrghhh!! CSS and Servlet again > > > In a typical web application server, there can be applications deployed to > several contexts within the container. Each context is differentiated using a > URL prefix, e.g.: > > http://myhost/webstore > http://myhost/benefits-admin > > Webstore and benefits-admin represent different Servlet contexts which are > different applications served out of the same container. In most cases, these > applications won't share resources, so the css files for the webstore > application will be somewhere below the document root for webstore, and the css > files for benefits-admin will be under it's document root, e.g.: > > /deploy/webapps/webstore/styles/main.css > /deploy/webapps/benefits-admin/styles/main.css > > When you refer to the main.css file for the webstore app, it's URI is > http://myhost/webstore/styles/main.css, or shortened to > /webstore/styles/main.css. For benefits-admin, it's > /benefits-admin/styles/main.css. > > The prefix part (/webstore, or /benefits-admin) is the "context path" and it is > defined in your application deployment descriptor. This can be changed during > deployment, so you don't want it hard coded in your HTML, JSP, or Servlets. > > It is possible to use relative paths to get to the URI, for example a servlet > whose URL is /webstore/servlet/MyServlet can refer to the css file as > ../styles/main.css, however that means that if you map a different URL to your > servlet, the relative URL won't work anymore. Also, take an example of a JSP > found at /webstore/cart.jsp. The relative URL of styles/main.css would work, > but what happens if the cart.jsp is redirected to from a servlet using a > RequestDispatcher? The browser thinks the URL is > /webstore/servlet/DirectorServlet, so the relative URL breaks! > > Explicity referring to the context path and appending the absolute path to the > resource within the deployed web application ensures that the reference will > always work, so long as the resource is in the location specified by the > absolute path. > > Obviously this is all irrelevant if you only have one context in your > application server and it is deployed to the web site root. > > John H. > > > > > "Robert Koberg" <[EMAIL PROTECTED]>@orionserver.co
Re: Aaarrrghhh!! CSS and Servlet again
Hi John, I see why you are doing that but I don't agree it is a good way to go, at least for me. It looks like you are a corporate developer who builds for an intranet that would benefit from the context paths. But, for me (internet development - each site unique), it works out better for the whole team when the dev (and qa) server is setup with virtual hosts (? I am not a sys admin, so...): Dev server dev-site1.workingdomain.com dev-site2.workingdomain.com QA server qa-site1.workingdomain.com qa-site2.workingdomain.com Live server(s) www.site1.com www.site2.com This way everyone is working (and qa'ing) out of the same environment as it will be when live. As for my personal development, I do work on local machines at home (not the dev box) whenever possible. We keep everything in sync with CVS. I also have the 5 static IPs and keep a machine/static IP for each project. It is easier for me (and everyone else on the team) to work without the context path. I do see the context path as a problem in these containers especially when working on large projects/groups with a variety of skills and needs. I feel it is better to keep the same environment through the site promotion process. of course there are other ways to do it... Thanks for the discussion, Rob - Original Message - From: <[EMAIL PROTECTED]> To: "Orion-Interest" <[EMAIL PROTECTED]> Sent: Thursday, June 21, 2001 3:34 PM Subject: Re: Aaarrrghhh!! CSS and Servlet again > > > In a typical web application server, there can be applications deployed to > several contexts within the container. Each context is differentiated using a > URL prefix, e.g.: > > http://myhost/webstore > http://myhost/benefits-admin > > Webstore and benefits-admin represent different Servlet contexts which are > different applications served out of the same container. In most cases, these > applications won't share resources, so the css files for the webstore > application will be somewhere below the document root for webstore, and the css > files for benefits-admin will be under it's document root, e.g.: > > /deploy/webapps/webstore/styles/main.css > /deploy/webapps/benefits-admin/styles/main.css > > When you refer to the main.css file for the webstore app, it's URI is > http://myhost/webstore/styles/main.css, or shortened to > /webstore/styles/main.css. For benefits-admin, it's > /benefits-admin/styles/main.css. > > The prefix part (/webstore, or /benefits-admin) is the "context path" and it is > defined in your application deployment descriptor. This can be changed during > deployment, so you don't want it hard coded in your HTML, JSP, or Servlets. > > It is possible to use relative paths to get to the URI, for example a servlet > whose URL is /webstore/servlet/MyServlet can refer to the css file as > ../styles/main.css, however that means that if you map a different URL to your > servlet, the relative URL won't work anymore. Also, take an example of a JSP > found at /webstore/cart.jsp. The relative URL of styles/main.css would work, > but what happens if the cart.jsp is redirected to from a servlet using a > RequestDispatcher? The browser thinks the URL is > /webstore/servlet/DirectorServlet, so the relative URL breaks! > > Explicity referring to the context path and appending the absolute path to the > resource within the deployed web application ensures that the reference will > always work, so long as the resource is in the location specified by the > absolute path. > > Obviously this is all irrelevant if you only have one context in your > application server and it is deployed to the web site root. > > John H. > > > > > "Robert Koberg" <[EMAIL PROTECTED]>@orionserver.com on 06/21/2001 01:28:51 PM > > Please respond to Orion-Interest <[EMAIL PROTECTED]> > > Sent by: [EMAIL PROTECTED] > > > To: Orion-Interest <[EMAIL PROTECTED]> > cc: > > Subject: Re: Aaarrrghhh!! CSS and Servlet again > > > > To be safe, you really ought to use request.getContextPath() to prefix the > > absolute URL of your css file relative to your document root. > > why (just curious)? > > what is different if just use: > > > > The above is more generic (you don't need to run JSP for every file) > > > > > - Original Message - > From: <[EMAIL PROTECTED]> > To: "Orion-Interest" <[EMAIL PROTECTED]> > Sent: Thursday, June 21, 2001 7:29 AM > Subject: RE: Aaarrrghhh!! CSS and Servlet again > > > > > > > > To be safe, you really ought to use request.getContextPath() to prefix the > > absolute URL of your css file relative to your document root. When you > deploy > > t
Re: Aaarrrghhh!! CSS and Servlet again
In a typical web application server, there can be applications deployed to several contexts within the container. Each context is differentiated using a URL prefix, e.g.: http://myhost/webstore http://myhost/benefits-admin Webstore and benefits-admin represent different Servlet contexts which are different applications served out of the same container. In most cases, these applications won't share resources, so the css files for the webstore application will be somewhere below the document root for webstore, and the css files for benefits-admin will be under it's document root, e.g.: /deploy/webapps/webstore/styles/main.css /deploy/webapps/benefits-admin/styles/main.css When you refer to the main.css file for the webstore app, it's URI is http://myhost/webstore/styles/main.css, or shortened to /webstore/styles/main.css. For benefits-admin, it's /benefits-admin/styles/main.css. The prefix part (/webstore, or /benefits-admin) is the "context path" and it is defined in your application deployment descriptor. This can be changed during deployment, so you don't want it hard coded in your HTML, JSP, or Servlets. It is possible to use relative paths to get to the URI, for example a servlet whose URL is /webstore/servlet/MyServlet can refer to the css file as ../styles/main.css, however that means that if you map a different URL to your servlet, the relative URL won't work anymore. Also, take an example of a JSP found at /webstore/cart.jsp. The relative URL of styles/main.css would work, but what happens if the cart.jsp is redirected to from a servlet using a RequestDispatcher? The browser thinks the URL is /webstore/servlet/DirectorServlet, so the relative URL breaks! Explicity referring to the context path and appending the absolute path to the resource within the deployed web application ensures that the reference will always work, so long as the resource is in the location specified by the absolute path. Obviously this is all irrelevant if you only have one context in your application server and it is deployed to the web site root. John H. "Robert Koberg" <[EMAIL PROTECTED]>@orionserver.com on 06/21/2001 01:28:51 PM Please respond to Orion-Interest <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] To: Orion-Interest <[EMAIL PROTECTED]> cc: Subject: Re: Aaarrrghhh!! CSS and Servlet again > To be safe, you really ought to use request.getContextPath() to prefix the > absolute URL of your css file relative to your document root. why (just curious)? what is different if just use: The above is more generic (you don't need to run JSP for every file) - Original Message - From: <[EMAIL PROTECTED]> To: "Orion-Interest" <[EMAIL PROTECTED]> Sent: Thursday, June 21, 2001 7:29 AM Subject: RE: Aaarrrghhh!! CSS and Servlet again > > > To be safe, you really ought to use request.getContextPath() to prefix the > absolute URL of your css file relative to your document root. When you deploy > to a context like: > > http://myhost:myport/mycontext > > All of your paths are prefixed by /mycontext. But if you change your deployment > descriptor, you might change "mycontext" to something else. You don't want that > hard-coded into your servlets. Also, the suggestion by elephantwalker is true - > you can use relative paths (/mycontext/servlet/../blah.css will get you to > /mycontext/blah.css) but if you decide to put your servlet in a package, or map > a different URL pattern to it (e.g. /mycontext/MyServlet) this won't work. > Using request.getContextPath() plus an absolute path is guaranteed to work so > long as the resource stays where you put it relative to the document root. It > also comes in very handy when you put the reference in a JSP - sometimes the JSP > will be called directly (so the browser URL is /mycontext/myjsp.jsp) but > sometimes you get there using a RequestDispatcher, so the browser thinks the URL > is /mycontext/servlet/MyServlet. In this case, relative URLs don't work. > > So, put the css file in your document root and use: > > > > if your JSPs and > > out.println(" request.getContextPath() + "/blah.css\" title=\"blah\">"); > > in your servlets. > > John H. > > > > > > "elephantwalker" <[EMAIL PROTECTED]>@orionserver.com on 06/20/2001 > 05:55:45 PM > > Please respond to Orion-Interest <[EMAIL PROTECTED]> > > Sent by: [EMAIL PROTECTED] > > > To: Orion-Interest <[EMAIL PROTECTED]> > cc: > > Subject: RE: Aaarrrghhh!! CSS and Servlet again > > > > The url pattern for your servlet is the issue. Somehow it is "/", which means > just about everthing. I would use something different like, /employees
Re: Aaarrrghhh!! CSS and Servlet again
> To be safe, you really ought to use request.getContextPath() to prefix the > absolute URL of your css file relative to your document root. why (just curious)? what is different if just use: The above is more generic (you don't need to run JSP for every file) - Original Message - From: <[EMAIL PROTECTED]> To: "Orion-Interest" <[EMAIL PROTECTED]> Sent: Thursday, June 21, 2001 7:29 AM Subject: RE: Aaarrrghhh!! CSS and Servlet again > > > To be safe, you really ought to use request.getContextPath() to prefix the > absolute URL of your css file relative to your document root. When you deploy > to a context like: > > http://myhost:myport/mycontext > > All of your paths are prefixed by /mycontext. But if you change your deployment > descriptor, you might change "mycontext" to something else. You don't want that > hard-coded into your servlets. Also, the suggestion by elephantwalker is true - > you can use relative paths (/mycontext/servlet/../blah.css will get you to > /mycontext/blah.css) but if you decide to put your servlet in a package, or map > a different URL pattern to it (e.g. /mycontext/MyServlet) this won't work. > Using request.getContextPath() plus an absolute path is guaranteed to work so > long as the resource stays where you put it relative to the document root. It > also comes in very handy when you put the reference in a JSP - sometimes the JSP > will be called directly (so the browser URL is /mycontext/myjsp.jsp) but > sometimes you get there using a RequestDispatcher, so the browser thinks the URL > is /mycontext/servlet/MyServlet. In this case, relative URLs don't work. > > So, put the css file in your document root and use: > > > > if your JSPs and > > out.println(" request.getContextPath() + "/blah.css\" title=\"blah\">"); > > in your servlets. > > John H. > > > > > > "elephantwalker" <[EMAIL PROTECTED]>@orionserver.com on 06/20/2001 > 05:55:45 PM > > Please respond to Orion-Interest <[EMAIL PROTECTED]> > > Sent by: [EMAIL PROTECTED] > > > To: Orion-Interest <[EMAIL PROTECTED]> > cc: > > Subject: RE: Aaarrrghhh!! CSS and Servlet again > > > > The url pattern for your servlet is the issue. Somehow it is "/", which means > just about everthing. I would use something different like, /employees or > /employees.html. Your path to the css should be just "../blah.css", and include > the blah.css in your war file at the root. > > regards, > > the elephantwalker > > > > > > > -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Brynolf Andersson Sent: Wednesday, June 20, 2001 3:28 PM To: Orion-Interest Subject: Aaarrrghhh!! CSS and Servlet again Hi all again, I have been trying all lot of different ways to pick uppthe CSS file but without any success. So I'll try to see if anyone has some more thing to add to my problem. The question is still there, where should I put my CSS file and how should I pick it up from the servlet. Som information: server.xml: default-web-site.xml: web.xml: http://java.sun.com/j2ee/dtds/web-app_2_2.dtd";> Lab 01 desc EmployeeServlet training.EmployeeServlet training.EmployeeServlet / --> application.xml: http://java.sun.com/j2ee/dtds/application_1_2.dtd";> Lab01 web / Directory structure of the WEB-APP: _lab_01 |_META-INF | |_application.xml |_web ||WEB-INF ||web.xml ||classes ||pkg ||myServlet Help Get your FREE download of MSN Explorer at http://explorer.msn.com
RE: Aaarrrghhh!! CSS and Servlet again
To be safe, you really ought to use request.getContextPath() to prefix the absolute URL of your css file relative to your document root. When you deploy to a context like: http://myhost:myport/mycontext All of your paths are prefixed by /mycontext. But if you change your deployment descriptor, you might change "mycontext" to something else. You don't want that hard-coded into your servlets. Also, the suggestion by elephantwalker is true - you can use relative paths (/mycontext/servlet/../blah.css will get you to /mycontext/blah.css) but if you decide to put your servlet in a package, or map a different URL pattern to it (e.g. /mycontext/MyServlet) this won't work. Using request.getContextPath() plus an absolute path is guaranteed to work so long as the resource stays where you put it relative to the document root. It also comes in very handy when you put the reference in a JSP - sometimes the JSP will be called directly (so the browser URL is /mycontext/myjsp.jsp) but sometimes you get there using a RequestDispatcher, so the browser thinks the URL is /mycontext/servlet/MyServlet. In this case, relative URLs don't work. So, put the css file in your document root and use: if your JSPs and out.println(""); in your servlets. John H. "elephantwalker" <[EMAIL PROTECTED]>@orionserver.com on 06/20/2001 05:55:45 PM Please respond to Orion-Interest <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] To: Orion-Interest <[EMAIL PROTECTED]> cc: Subject: RE: Aaarrrghhh!! CSS and Servlet again The url pattern for your servlet is the issue. Somehow it is "/", which means just about everthing. I would use something different like, /employees or /employees.html. Your path to the css should be just "../blah.css", and include the blah.css in your war file at the root. regards, the elephantwalker -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Brynolf Andersson Sent: Wednesday, June 20, 2001 3:28 PM To: Orion-Interest Subject: Aaarrrghhh!! CSS and Servlet again Hi all again, I have been trying all lot of different ways to pick uppthe CSS file but without any success. So I'll try to see if anyone has some more thing to add to my problem. The question is still there, where should I put my CSS file and how should I pick it up from the servlet. Som information: server.xml: default-web-site.xml: web.xml: http://java.sun.com/j2ee/dtds/web-app_2_2.dtd";> Lab 01 desc EmployeeServlet training.EmployeeServlet training.EmployeeServlet / --> application.xml: http://java.sun.com/j2ee/dtds/application_1_2.dtd";> Lab01 web / Directory structure of the WEB-APP: _lab_01 |_META-INF | |_application.xml |_web ||WEB-INF ||web.xml ||classes ||pkg ||myServlet Help Get your FREE download of MSN Explorer at http://explorer.msn.com
Re: Aaarrrghhh!! CSS and Servlet again
You are misunderstanding when the CSS gets used. CSS is client-side. When the browser parses the html you send, it will see the tag and download the external css document to apply styles. A simple way to deal with this is have your CSS off the document root or in a sub-dir just off the doc-root: REL="stylesheet" TYPE="text/css" HREF="/css/mycss.css" > so, the file could be dowloaded if someone typed in this URL: http://www.abc.com/css/mycss.css HTH - Original Message - From: Brynolf Andersson To: Orion-Interest Sent: Wednesday, June 20, 2001 3:28 PM Subject: Aaarrrghhh!! CSS and Servlet again Hi all again,I have been trying all lot of different ways to pick uppthe CSS file but without any success. So I'll try to see if anyone has some more thing to add to my problem. The question is still there, where should I put my CSS file and how should I pick it up from the servlet. Som information:server.xml: default-web-site.xml: web.xml: Lab 01descEmployeeServlettraining.EmployeeServlettraining.EmployeeServlet/ --> application.xml: Lab01web/ Directory structure of the WEB-APP:_lab_01|_META-INF| |_application.xml|_web||WEB-INF||web.xml||classes||pkg||myServlet Help Get your FREE download of MSN Explorer at http://explorer.msn.com
RE: Aaarrrghhh!! CSS and Servlet again
The url pattern for your servlet is the issue. Somehow it is "/", which means just about everthing. I would use something different like, /employees or /employees.html. Your path to the css should be just "../blah.css", and include the blah.css in your war file at the root. regards, the elephantwalker -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Brynolf AnderssonSent: Wednesday, June 20, 2001 3:28 PM To: Orion-InterestSubject: Aaarrrghhh!! CSS and Servlet again Hi all again,I have been trying all lot of different ways to pick uppthe CSS file but without any success. So I'll try to see if anyone has some more thing to add to my problem. The question is still there, where should I put my CSS file and how should I pick it up from the servlet. Som information:server.xml: default-web-site.xml: web.xml: Lab 01descEmployeeServlettraining.EmployeeServlettraining.EmployeeServlet/ --> application.xml: Lab01web/ Directory structure of the WEB-APP:_lab_01|_META-INF| |_application.xml|_web||WEB-INF||web.xml||classes||pkg||myServlet Help Get your FREE download of MSN Explorer at http://explorer.msn.com
Aaarrrghhh!! CSS and Servlet again
Hi all again,I have been trying all lot of different ways to pick uppthe CSS file but without any success. So I'll try to see if anyone has some more thing to add to my problem. The question is still there, where should I put my CSS file and how should I pick it up from the servlet. Som information:server.xml: default-web-site.xml: web.xml: Lab 01descEmployeeServlettraining.EmployeeServlettraining.EmployeeServlet/ --> application.xml: Lab01web/ Directory structure of the WEB-APP:_lab_01|_META-INF| |_application.xml|_web||WEB-INF||web.xml||classes||pkg||myServlet HelpGet your FREE download of MSN Explorer at http://explorer.msn.com