![]() | ![]() | ![]() |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Web applications are configured with the web-app tag, which can occur in a number of places.
Resin Web Applicationscache-mappingchild of web-app-default, web-appSpecifies times for cacheable pages.cache-mapping is intended to provide Expires times for pages that have Last-Modified or ETags specified, but do not wish to hard-code the Expires timeout in the servlet. For example, Resin's FileServlet relies on cache-mapping to set the expires times for static pages.
The time interval defaults to seconds, but will allow other periods:
<web-app id='/'> <cache-mapping url-pattern='/*' expires='10'/> <cache-mapping url-pattern='*.gif' expires='15m'/> </web-app> config-filechild of web-app-default, web-appSpecifies configuration files for the web-app. The use of files like WEB-INF/web.xml and WEB-INF/resin-web.xml are configured using <config-file>. You can add application-specific configuration files using the <config-file> tag. Configuration files will be read and applied in the order they are specified. ... <config-file>WEB-INF/web.xml</config-file> <config-file>WEB-INF/resin-web.xml</config-file> ... ear-deploychild of host, web-appSpecifies ear expansion. ear-deploy can be used in web-apps to define a subdirectory for ear expansion.
jspchild of web-app-default, web-appConfigures JSP behavior.
The class that corresponds to <jsp> is com.caucho.jsp.cfg.JspPropertyGroup multipart-formchild of web-app-default, web-appEnables multipart-mime for forms and file uploads. multipart-mime is disabled by default. For an uploaded file with a form name of , the parameter value contains the path name to a temporary file containing the uploaded file. contains the uploaded filename, and contains the content-type of the uploaded file.
If the upload is larger than the limit or if multipart-form processing is disabled, Resin will not parse the request and will set an error message in the " " request attribute. The " " will contain the attempted upload size.Requests can set the maximum by setting the request attribute " " with an Integer or Long value.By default, multipart-form is disabled. path-mappingchild of web-app-default, web-appMaps url patterns to real paths. If using a server like IIS, you may need to match the server's path aliases.
<web-app id='/'> <path-mapping url-pattern='/resin/*' real-path='e:\resin'/> <path-mapping url-regexp='/~([^/]*)' real-path='e:\home\$1'/> </web-app> shutdown-wait-maxThe maximum time Resin will wait for requests to finish before closing the web-app. strict-mappingdefault false, allowing /foo/bar.jsp/foo.Forces servlet-mapping to follow strict Servlet 2.2, disallowing PATH_INFO. Value is or .<web-app> <strict-mapping>true</strict-mapping> </web-app> web-app-defaultchild of server, host-default, hostEstablishes the defaults for a web-app. When initializing a web-app, all the tags in the web-app-defaults sections configure the web-app. In other words, the web-app-default value is essentially a macro that is cut-and-pasted before the web-app configuration. web-app-default is used for defining server-wide behavior, like *.jsp handling, and for host-wide behavior. <host> <web-app-default> <servlet servlet-name='test' servlet-class='test.MyServlet'/> <servlet-mapping url-pattern='*.text' servlet-class='test'/> </web-app-default> </host> web-appchild of host-default, host, WEB-INF/web.xml, WEB-INF/resin-web.xmlweb-app configures a web application.
When specified by , the application will be initialized on server start. When specified by , the application will be initialized at the first request. This means that servlets may start later than expected for applications.The following example creates a web-app for /apache using the Apache htdocs directory to serve pages. <host id=''> <web-app id='/apache' document-directory='/usr/local/apache/htdocs'> ... </host> The following example sets the root web-app to the IIS root directory. <web-app id='/' document-directory='C:/inetpub/wwwroot'> When the is specified with a , can use replacement variables ( ).In the following, each user gets his or her own independent application using .<host id=''> <web-app url-regexp='/~([^/]*)' document-directory='/home/$1/public_html'> ... </web-app> </host> web-app-deploychild of host, web-appSpecifies war expansion. web-app-deploy can be used in web-apps to define a subdirectory for war expansion. The tutorials in the documentation use web-app-deploy to allow servlet/tutorial/helloworld to be an independent war file.
The web-app-deploy can override configuration for an expanded war with a matching <web-app> inside the <web-app-deploy>. The <document-directory> is used to match web-apps. <web-app-deploy path="webapps"> <web-app context-path="/wiki" document-directory="wiki"> <context-param database="jdbc/wiki"> </web-app> </web-app-deploy> Servlet 2.4Resin implements the Servlet 2.4 specification. descriptiondisplay-namedistributablecontext-paramchild of web-appInitializes application (ServletContext) variables. <web-app id='/'> <context-param> <param-name>baz</param-name> <param-value>value</param-value> </context-param> <!-- shortcut --> <context-param foo='bar'/> </web-app> filterDefines a filter alias for later mapping.
The following example defines a filter alias 'image' <web-app id='/'> <filter> <filter-name>image</filter-name> <filter-class>test.MyImage</filter-class> <init-param> <param-name>title</param-name> <param-value>Hello, World</param-value> </init-param> </filter> <filter-mapping> <filter-name>image</filter-name> <url-pattern>/images/*</url-pattern> </filter-mapping> </web-app> The full Servlet 2.3 syntax for is supported as well as a simple shortcut.<web-app id='/'> <filter filter-name='test.HelloWorld'> <init-param foo='bar'/> <init-param> <param-name>baz</param-name> <param-value>value</param-value> </init-param> </servlet> </web-app> filter-mappingMaps url patterns to filters. has two children, and . selects the urls which should execute the filter.
<web-app> <filter> <filter-name>test-filter</filter-name> <filter-class>test.MyFilter</filter-class> </filter> <filter-mapping> <filter-name>test-filter</filter-name> <url-pattern>/hello/*</url-pattern> </filter-mapping> <servlet> <servlet-name>hello</servlet-name> <servlet-class>test.HelloWorld</servlet-class> </servlet> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping> </web-app> listenerservletDefines a servlet alias for later mapping using servlet-mapping.
<web-app id='/'> <servlet> <servlet-name>hello</servlet-name> <servlet-class>test.HelloWorld</servlet-class> <init-param> <param-name>title</param-name> <param-value>Hello, World</param-value> </init-param> </servlet> <!-- using Resin shortcut syntax --> <servlet servlet-name='cron' servlet-class='test.DailyChores'> <init-param title='Daily Chores'/> <load-on-startup/> <run-at>3:00</run-at> </servlet> <!-- mapping a url to use the servlet --> <servlet-mapping url-pattern='/hello.html' servlet-name='hello'/> </web-app> Several configurations might configure the same servlet class with different values. Each will have a separate .<web-app> <servlet servlet-name='foo-a'> <servlet-class>test.FooServlet</servlet-class> <init-param name='foo-a sample'/> </servlet> <servlet servlet-name='foo-b'> <servlet-class>test.FooServlet</servlet-class> <init-param name='foo-b sample'/> </servlet> </web-app> can specify an (optional) integer value. If the value is 0 or greater, it indicates an order for servlets to be loaded, servlets with higher numbers get loaded after servlets with lower numbers. There are a number of named servlets that are usually available to a Resin application, as defined in .<servlet servlet-name="directory" servlet-class="com.caucho.servlets.DirectoryServlet"/> <servlet servlet-name="file" servlet-class="com.caucho.servlets.FileServlet"/> <servlet servlet-name="jsp" servlet-class="com.caucho.jsp.JspServlet"/> <servlet servlet-name="xtp" servlet-class="com.caucho.jsp.XtpServlet"/> <servlet servlet-name="j_security_check" servlet-class="com.caucho.server.security.FormLoginServlet"/> servlet-mappingMaps url patterns to servlets. has two children, and . selects the urls which should execute the servlet.
<web-app id='/'> <servlet> <servlet-name>hello</servlet-name> <servlet-class>test.HelloWorld</servlet-class> </servlet> <servlet-mapping> <url-pattern>/hello.html</servlet-class> <servlet-name>hello</servlet-class> </servlet-mapping> <!-- resin shortcut syntax --> <servlet-mapping url-pattern='*.xtp' servlet-name='com.caucho.jsp.XtpServlet'/> </web-app> In Resin, the special <web-app id='/'> <!-- used with urls like http://localhost:8080/servlets/test.HelloServlet --> <servlet-mapping url-pattern="/servlet/*" servlet-name="invoker"/> </web-app> There are a number of mappings to servlets that are usually available to a Resin application, as defined in .<servlet-mapping url-pattern="*.jsp" servlet-name="jsp"/> <servlet-mapping url-pattern="*.xtp" servlet-name="xtp"/> <servlet-mapping url-pattern="/servlet/*" servlet-name="invoker"/> <servlet-mapping url-pattern="/" servlet-name="file"/> The plugins use servlet-mapping to decide which URLs to send to Resin. The following servlet-name values are used by the plugins:
servlet-regexpMaps URL by regular expressions to custom servlets. <servlet-regexp url-regexp="/([^.]*).do" servlet-class="qa.\${regexp[1]}Servlet"> <init a="b"/> </servlet-regexp> session-configSession configuration parameters.
Resin add's a number of tags.
By default, both <web-app id='/'> <session-config enable-cookies='false' enable-url-rewriting='true'/> </web-app> The <web-app id='/dir'> <session-config> <!-- 2 hour timeout --> <session-timeout>120</session-timeout> <session-max>4096</session-max> </session-config> </web-app> is used to limit the maximum length for the session's generated cookie for special situations like WAP devices. Reducing this value reduces the randomness in the cookie and increases the chance of session collisions. defaults to true so that Resin can share the session id amongst different web-apps. The class that corresponds to <session-config> is com.caucho.server.session.SessionManager mime-mappingchild of web-app-default, web-appMaps url patterns to mime-types.
<web-app id='/'> <mime-mapping> <extension>.foo</extension> <mime-type>text/html</mime-type> </mime-mapping> <!-- resin shortcut syntax --> <mime-mapping extension='.bar' mime-type='text/html'/> </web-app> Resin has a long list of default mime types in welcome-file-listchild of web-app-default, web-appdefault in $RESIN_HOME/conf/app-default.xml is index.xtp, index.jsp, index.html.Sets the files to use as when no filename is present in url. According to the spec, each file is in a <welcome-file> element. <web-app id='/'> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.xtp</welcome-file> <welcome-file>home.xtp</welcome-file> </welcome-file-list> </web-app> Resin also provides a shortcut where you can just list the files: <web-app id='/'> <welcome-file-list> index.jsp, index.xtp, home.xtp </welcome-file-list> </web-app> error-pagechild of web-app-default, web-app
By default, Resin returns a 500 Servlet Error and a stack trace for exceptions and a simple 404 File Not Found for error pages. Applications can customize the response generated for errors. <web-app> <error-page> <error-code>404</error-code> <location>/file_not_found.jsp</location> </error-page> </web-app> <web-app id='/foo'> <error-page exception-type='java.lang.NullPointerException' location='/nullpointer.jsp'/> </web-app> The error page can use request attributes to obtain information about the request that caused the error: <%@ page session="false" isErrorPage="true" %> <html> <head><title>404 Not Found</title></head> <body> <h1>404 Not Found</h1> The url <code>${'${'}requestScope["javax.servlet.error.request_uri"]}</code> was not found. </body> </html> Request attributes for error handling
jsp-configresource-env-refmessage-destination-refresource-refsecurity-constraintchild of web-app-default, web-appSpecifies protected areas of the web site. Sites using authentication as an optional personalization feature will typically not use any security constraints. Security constraints can also be custom classes. <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint role-name='user'> </security-constraint> display-namechild of security-constraintweb-resource-collectionchild of security-constraintSpecifies a collection of areas of the web site.
auth-constraintchild of security-constraintRequires that authenticated users fill the specified role. In Resin's JdbcAuthenticator, normal users are in the "user" role. Think of a role as a group of users.
user-data-constraintchild of security-constraintRestricts access to secure transports, such as SSL
constraintchild of security-constraintDefines a custom constraint.
login-configchild of web-app-default, web-appdefault no authentication
HTTP Authentication is defined in the RFC HTTP Authentication: Basic and Digest. HTTP digest authentication is discussed in Digest Passwords. form-login-configchild of login-configConfigures authentication using forms. The login form has specific parameters that the servlet engine's login form processing understands. If the login succeeds, the user will see the original page. If it fails, she will see the error page.
The form itself must have the action . It must also have the parameters and . Optionally, it can also have and . gives the next page to display when login succeeds. allows Resin to send a persistent cookie to the user to make following login easier.gives control to the user whether to generate a persistent cookie. It lets you implement the "remember me" button. By default, the authentication only lasts for a single session.
The following is an example of a servlet-standard login page: <form action='j_security_check' method='POST'> <table> <tr><td>User:<td><input name='j_username'> <tr><td>Password:<td><input name='j_password'> <tr><td colspan=2>hint: the password is 'quidditch' <tr><td><input type=submit> </table> </form> security-roleenv-entryejb-refchild of web-app-default, web-appejb-local-refchild of web-app-default, web-appmessage-destinationlocale-encoding-mapping-list
|