caucho
Resin
FAQ
Reference Guide
Demo
Tutorial

Installation
SSL
Class Loader
Configuration
JSP/Servlet
Debugging
Misc
 Configuration

Class Loader
FAQ
JSP/Servlet

  1. How do I change the work directory?
  2. How do I use multiple resin.conf files?
  3. How do I configure a default servlet?
  4. How do I change the 'cannot connect' message?
  5. How do I set a virtual directory?
  6. What is a web-app?
  7. Why don't my URLs work in my web-app?
  8. How do I use virtual hosts with IIS?
  9. How do I configure error pages in resin.conf?
  10. Where do all the files go?
  11. How do I disable directory browsing?
  12. Why do both virtual hosts use the same index.jsp file?
  13. How do I use a servlet as the welcome page?

How do I change the work directory?

<work-dir>.

By default, that's /tmp/caucho on Unix and \temp\caucho on Windows.

How do I use multiple resin.conf files?

This is especially important if you want to use a different workspace for development than deployment. Just call the httpd executable with the -conf flag.

unix> httpd.sh start -conf devel.conf -verbose

d:\> httpd.exe -conf devel.conf -verbose

How do I configure a default servlet?

The following will a servlet to handle all unmatched URLs, just like the FileServlet does by default.

<servlet-mapping url-pattern='/' servlet-name='MyServlet'/>

This has a different effect from url-pattern='/*'. /* will have priority over extension mappings like *.jsp, while / has the lowest priority.

How do I change the 'cannot connect' message?

In the resin.conf, add an error-page directive using connection for the exception type. The location must be an absolute path understandable to your web server. For example, since the web server will display this message, you can't forward to a jsp file.

<error-page exception-type='connection' location='/errorpage.html'/>

How do I set a virtual directory?

Use the <path-mapping> directive. For example, to grab images from /home/images/*, use:

<path-mapping url-pattern='/images/*' real-path='/home/images'/>

What is a web-app?

The vast majority of sites can completely ignore web-apps. If you're starting with Resin, use the default web-app and don't worry about it.

You'll only want to use web-apps when you want separate projects using the same web server. For example, on an ISP site, each user might get her own web-app. She can treat the web-app as if she had control over the whole web server starting at a URL prefix like ~karen.

A web-app is a generalization of a virtual host. With virtual hosts, each host pretends that it controls its own server when it really is sharing the server with other virtual hosts. A web-app extends this by creating virtual applications for a URL prefix.

Each web-app gets its own sessions, servlets, beans and static pages.

Why don't my URLs work in my web-app?

Remember, the browser doesn't know about your web-apps. It treats the web server as a single URL-space. This may cause you troubles if you use a standard directory structure like putting images in '/images/*'.

To see this problem, suppose you have a web-app called '/myproject'. Suppose you have a JSP page in the web-app called foo/bar.jsp. The full URL will be /myproject/foo/bar.jsp. Your image reference should look like one of the following:

<img src='../images/image1.gif'/>
<img src='<%= application.getContextPath() %>/images/image1.gif'/>

Using /images/image1.gif will fail because the browser will look for http://myhost.com/images/image1.gif when you really want http://myhost.com/myproject/images/image1.gif.

How do I use virtual hosts with IIS?

Jan Venema replies,

This is my working config under IIS 4.0 end Resin1.1b6

<caucho.com>
  <http-server>
    <error-log id='log/default-error.log'/>

    <!--
      -- Each virtual host has its own applications, sessions,
      -- and servlets.  You must duplicate the configuration for
      -- each host.  Each host ignores the configuration in
      -- the outer block.
      -->

    <host id='192.168.0.2'>
      <app-dir>d:\inetpub\wwwroot\inverko</app-dir>
      <error-log id='d:\inetpub\wwwroot\inverko\error.log'/>
      <servlet-mapping url-pattern='/servlet/*'
                       servlet-name='invoker'/>
      <servlet-mapping url-pattern='*.jsp'
                       servlet-name='com.caucho.jsp.JspServlet'/>
    </host>

    <host id='192.168.0.3'>
      <app-dir>d:\inetpub\wwwroot\dmd</app-dir>
      <error-log id='d:\inetpub\wwwroot\dmd\error.log'/>
      <servlet-mapping url-pattern='/servlet/*'
                       servlet-name='invoker'/>
      <servlet-mapping url-pattern='*.jsp'
                       servlet-name='com.caucho.jsp.JspServlet'/>
    </host>
  </http-server>
</caucho.com>

How do I configure error pages in resin.conf?

The basic command is error-page. There are three kinds of error pages

  • Error code pages, e.g. 404
  • Exception, e.g. java.lang.NullPointerException
  • connection failures, "can't connect to srun"

Where do all the files go?

The document root is set in resin.conf using the app-dir:

<http-server app-dir='/www/htdocs'>
  ...
</http-server>

Each virtual host and each web-app will have its own app-dir. The app-dir configuration must be in resin.conf, not the web.xml (otherwise Resin couldn't find web.xml):

<web-app id='myapp' app-dir='/www/myapp'>
   ...
</web-app>

If you don't specify an app-dir, Resin will use id looking in /www/htdocs/myapp in the above example.

Optionally, you can put a web.xml in [app-dir]/WEB-INF/web.xml (again, following JSDK 2.2). The web.xml can contain anything the web-app in resin.conf can.

Auto-reloaded classes belong in [app-dir]/WEB-INF by default, following JSDK 2.2:

classes  -- auto-load/recompile Java servlet/bean/classes directory
lib -- auto-loaded *.jar files

In the web-app, you can add to the auto-reload classpath using:

<classpath id='myclasses' source='/home/work/proj/src' compile='true'/>

The JSP/Java work directory is /tmp/caucho (or \temp\caucho). You can change that with:

<java compiler='javac' work-dir='/path/to/my/work/dir'/>

Finally, the startup scripts will look for jars in resin1.1/lib to add to the classpath before starting resin.

How do I disable directory browsing?

Setting directory-servlet to "none" will disable directory browsing.

<web-app id='/'>
  <directory-servlet id='false'/>
</web-app>

Why do both virtual hosts use the same index.jsp file?

As described in the virtual host reference, you must use <host> and <app-dir> in your resin.conf to configure virtual hosts.

If you omit the <host>, Resin will generate the same class name for both hosts. So one host will see the JSP from the second host. By adding the <host>, Resin will make the class names unique.

How do I use a servlet as the welcome page?

There's no url-pattern that will only match '/'. url-pattern='/' will set the servlet as the default servlet, replacing the file servlet.

You'll need to use Resin's url-regexp. url-regexp='^/$' will do the trick.


Class Loader
FAQ
JSP/Servlet
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.