RE: Blending webapps with HTML files
Hi, I don't know if my approach qualifies as "best practice", but I do have a couple of comments to contribute to this thread.. I would just point out first that the following comments really applies to tomcat running "stand-alone". After re-reading your email, you appear to be talking about issues relating to using tomcat together with apache, which makes things more complicated As I see it, each "web application" should be regarded as completely independent. In fact, you might like to think of a separate host machine for each webapp, and a "router" machine that reads the server.xml file at startup; when a url is received by the router machine, it figures out what Context matches the url (finds a context with a path attribute which matches the first part of the url). The router then forwards the request to the machine for that Context (ie web application). If no context's path matches the first part of the incoming url, then the context whose path="" is selected. Of course, this would be pretty expensive :-) However, by clever use of class loaders, a servlet engine (like tomcat) can get almost the same effect using just a single machine and a single jvm. Web Applications run in a "pure" servlet engine *really* are separate from each other, it's not just an issue of having a different document root directory. Each web app has its own indivudual WEB-INF/web.xml file, so they can be configured very differently; different servlet classes, different servlet mappings, different mime type definitions, different parameters passed to servlets on init. And all classes under a web application's root directory are loaded by a class loader specific to that webapp, which has all sorts of subtle effects. Perhaps the following comments might clarify things? (a) each webapp has its own document root directory, specified in the Context tag. For those people too lazy to define Context tags explicitly, there is an auto-setup procedure which looks in dir $TOMCAT_HOME/webapps, and sets up a Context for each subdirectory it finds there. This does not mean that there *must* be a common root directory that all webapps hang off, that's just the way the auto-setup procedure works. (b) the ROOT example web application that comes with tomcat isn't "special" in any way. Its Context tag in the server.xml just happens to have a path attribute of "", which means that when a url like http://xyz/abc.html comes in, tomcat first tries to find a webapp whose path is "xyz", and if no such webapp exists, then tomcat passes the url off to the context (webapp) whose path="". In other words, the directory name "ROOT" could have been called "TheDefaultWebAppRootDir". I think part of your email is asking about how best to structure directories when the dynamic part of a web application's files are to be served by tomcat and the static part by a separate web server. As I use tomcat stand-alone, I can't comment on that. When using a "pure" tomcat solution, these problems just don't occur :-) However, I think that whatever solution you choose should comply with the "spirit" of the servlet spec, ie you should set up apache so that a user can't tell that they are not using pure tomcat (apart from speed). Having a system which fetches static pages from urls which have a different prefix from the dynamic part of the webapp is asking for trouble, I think. By the way, Geoff suggests putting libs in the global TOMCAT_HOME/lib directory. I think this is not a "best practice"; you might want to check the email archives for my email of 2000-12-27, with subject "RE: Servlet error I can't seem to resolve". Again, that's just my opinion but no-one shot it down... Regards, Simon -Original Message----- From: Geoff Lane [SMTP:[EMAIL PROTECTED]] Sent: Saturday, January 13, 2001 7:01 AM To: [EMAIL PROTECTED] Subject: Re: Blending webapps with HTML files First time posting to the list. So good to meet you all. :) David Wall wrote: I'm new to Tomcat 3.2.1 and Servlet 2.2 in particular, having just come from JRun before webapps made their debut. I'm struggling with the "best practices" people are using for storing their JSPs and Java class files in the webapps directory, while storing images and html files in the web server directory root. For example, in Apache 1.3.14, my document root is htdocs and I am putting some files there for serving by apache, like: htdocs/images/a.gif htdocs/images/b.gif htdocs/index.jsp -- empty dummy file workaround so that Apache will send a request for "/" to Tomcat's ROOT index.jsp htdocs/app.js htdocs/app.css etc... I've noticed the same thing with mapping a servlet to an index file (in my case I mapped it to index.html). I think you have to '
RE: Blending webapps with HTML files
You can put the jsp pages basically anywhere you want to. You just have to setup the context correctly in the server.xml file. Just add the WEB-INF directory to your sitemap and everything should work fine. Example: site is under [...]/htdocs/mysite then all classes are under [...]/htdocs/WEB-INF/classes the context would read something like this Context path="/mysite" docBase="[...]/htdocs/mysite"// just put the completepath here as the webbase for you site [etc...] /Context If you have setup your Apache Tomcat connection correct the jsp files should automatically be served to tomcat and with the above context set correctly the url gets automatically mapped to the correct context and therefor to the correct path. The result is your dynamic and static stuff can reside in the same directory structure!!! Stefan
Re: Blending webapps with HTML files
Isn't that just the result of the http server config? If the web server sends all requests to the servlet/JSP container, I think it will handle them OK in the webapp area. mfs David Wall wrote: I'm new to Tomcat 3.2.1 and Servlet 2.2 in particular, having just come from JRun before webapps made their debut. I'm struggling with the "best practices" people are using for storing their JSPs and Java class files in the webapps directory, while storing images and html files in the web server directory root. For example, in Apache 1.3.14, my document root is htdocs and I am putting some files there for serving by apache, like: htdocs/images/a.gifhtdocs/images/b.gifhtdocs/index.jsp -- empty dummy file workaround so that Apache will send a request for "/" to Tomcat's ROOT index.jsphtdocs/app.jshtdocs/app.cssetc... And in my webapps under Tomcat I have: webapps/ROOT/index.jsp-- the actual index.jsp served up when I enter "/" for apachewebapps/ROOT/WEB-INF/classes/ (all of my class files needed just by the index.jsp file)webapps/pub/index.jspwebapps/pub/company.jspwebapps/pub/news.jspwebapps/pub/WEB-INF/classes/ (all the class files needed by 'pub' application, even though they are the same as those for ROOT). My questions are: 1) This separation of the JSP files from stuff like images, javascripts, stylesheets when deployed seems like a pain since they need to be in the same directory when I'm using my editing tools (like Dreamweaver). Only when I deploy do I need to move the static files to the apache locations and the JSPs to the Tomcat webapps area. Don't others find this to be a pain, or I am just not doing it right? 2) The ROOT and pub applications are really not distinct applications, only a separation of JSPs and such from the root to a public directory. I had this subdirectory structure back before webapps, and they were done to organize the JSPs into logical groups like how all HTML sites are done. They are not put into separate subdirectories because they are separate webapps. Can a single webapp support multiple directories, or at least a directory and all subdirectories? Perhaps ROOT is just abnormal because everybody wants a page to be displayed when they enter your URL like http://myeastside.com/ 3) When Java classes are shared by several webapps, they have to appear in each of the webapps' WEB-INF/classes directories. Is that what people are doing, or are they JARing them up and then putting them in a common location (like Tomcat's 'lib') to be shared by all? Any thoughts will help. The separation forced by the webapps concept seems broken to me since it seems unlikely that web servers and their standard document root processing is not going to go away anytime soon (we still have PHP, CGI, images, etc. besides JSPs). David - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: Blending webapps with HTML files
First time posting to the list. So good to meet you all. :) David Wall wrote: I'm new to Tomcat 3.2.1 and Servlet 2.2 in particular, having just come from JRun before webapps made their debut. I'm struggling with the "best practices" people are using for storing their JSPs and Java class files in the webapps directory, while storing images and html files in the web server directory root. For example, in Apache 1.3.14, my document root is htdocs and I am putting some files there for serving by apache, like: htdocs/images/a.gif htdocs/images/b.gif htdocs/index.jsp -- empty dummy file workaround so that Apache will send a request for "/" to Tomcat's ROOT index.jsp htdocs/app.js htdocs/app.css etc... I've noticed the same thing with mapping a servlet to an index file (in my case I mapped it to index.html). I think you have to 'trick' the webserver into loading a file - if it doesn't find a default file to load it won't do anything. And in my webapps under Tomcat I have: webapps/ROOT/index.jsp-- the actual index.jsp served up when I enter "/" for apache webapps/ROOT/WEB-INF/classes/ (all of my class files needed just by the index.jsp file) webapps/pub/index.jsp webapps/pub/company.jsp webapps/pub/news.jsp webapps/pub/WEB-INF/classes/ (all the class files needed by 'pub' application, even though they are the same as those for ROOT). My questions are: 1) This separation of the JSP files from stuff like images, javascripts, stylesheets when deployed seems like a pain since they need to be in the same directory when I'm using my editing tools (like Dreamweaver). Only when I deploy do I need to move the static files to the apache locations and the JSPs to the Tomcat webapps area. Don't others find this to be a pain, or I am just not doing it right? 2) The ROOT and pub applications are really not distinct applications, only a separation of JSPs and such from the root to a public directory. I had this subdirectory structure back before webapps, and they were done to organize the JSPs into logical groups like how all HTML sites are done. They are not put into separate subdirectories because they are separate webapps. Can a single webapp support multiple directories, or at least a directory and all subdirectories? Perhaps ROOT is just abnormal because everybody wants a page to be displayed when they enter your URL like http://myeastside.com/ 3) When Java classes are shared by several webapps, they have to appear in each of the webapps' WEB-INF/classes directories. Is that what people are doing, or are they JARing them up and then putting them in a common location (like Tomcat's 'lib') to be shared by all? What I found - and prefer - is to put shared JARs in the $TOMCAT_HOME/lib directory. All of the applications will find them then and share the same ones. They can also be found/loaded if they are set in the CLASSPATH (on Unix I have a wrapper script that sets this before starting Tomcat). One example of something you have to have in the CLASSPATH and not the lib directory is the j2ee.jar if you access it - Tomcat won't start with it in the lib directory (probably because it declares the servlet stuff agina). Any thoughts will help. The separation forced by the webapps concept seems broken to me since it seems unlikely that web servers and their standard document root processing is not going to go away anytime soon (we still have PHP, CGI, images, etc. besides JSPs). David My understanding of webapps is that it is for autoconfiguring things. But it is completely optional. I'm exploring Tomcat at work and chose to intentionaly not use webapps so that we would force ourselves to explicitly control the configuration of the application. So, that being said, one thing you could do: in your server.xml file create a context or a virtual host and map it to the directory where the Apache docRoot lives. E.g.: (Forgive any errors, this is from memory) Host name="virtualhost" Context path="" docBase="c:/htdocs" / /Host Then under c:/htdocs you'll need your WEB-INF directory with it's web.xml file mapping *.jsp to the JSP engine, etc. I've never done this with JSPs, but it works with static files and servlets so I don't see why it wouldn't with them. Don't know if these are Best Practices, but they're working so far for me. :) -- --- Geoff Lane [EMAIL PROTECTED] 'For a list of the ways which technology has failed to improve our quality of life, press 3.' - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]