📄 servlet.xtp
字号:
<p>The usual case balances all requests to backend servers. The front-end Resininstance has a resin.xml similar to the one shown here. It configuresthe front-end instance to balance the load to the backendservers. The backend Resin instances have a resin.xml file thatconfigures the web site, similar to a conf file that is used when only oneinstance of Resin used for the server.</p><example title="frontend.conf"><resin xmlns="http://caucho.com/ns/resin"> <server> <http id='frontend' port='8080'/> <cluster id='backend'> <srun id='a' host='192.168.0.11' port='6810'/> <srun id='b' host='192.168.0.12' port='6810'/> </cluster> <!-- the front-end does the access logging --> <access-log path='log/access.log'> <rollover-period>2W</rollover-period> </access-log> <!-- all urls are load balanced to the backend --> <host id=''> <web-app id='/'> <servlet> <servlet-name>backend</servlet-name> <servlet-class>com.caucho.servlets.LoadBalanceServlet</servlet-class> <init> <cluster>backend</cluster> </init> </servlet> <servlet-mapping url-pattern='/*' servlet-name='backend'/> </web-app> </host> </server></resin></example><p>LoadBalanceServlet is also used to allow a separate JVM for a web-app or ahost.</p><p>The <var>strategy</var> determines the strategy to use for choosing a backendserver for a request that does not have a sticky-session. The`least-connection' strategy chooses the backend server that has the leastnumber of connections at the time the decision is made. This is a good generalpurpose strategy, and compensates for differences in a backend server's abilityto service connections. The `round-robin' strategy does a straight roundrobin, choosing the backend server that follows the last backend server chosen.</p><p>See <a href="javadoc|com.caucho.servlets.LoadBalanceServlet|"/>.</p></s1><s1 title="CGIServlet"><p>Implements CGI calls. The url is assumed to refer to an executable file,and the operating system is instructed to execute the program or script. Theusual CGI environment variables are set, and the current directory is the value of <code>$RESIN_HOME</code></p><deftable-parameters><tr><td>executable</td><td>Path to the script program</td><td>default exec</td></tr><tr><td>ignore-exit-code</td><td>If true, do not treat a non-zero exit code as an error</td><td>false</td></tr><tr><td>stderr-is-exception</td><td>If false, ignore output on stderr instead of triggering an exception</td><td>true</td></tr></deftable-parameters><example title="WEB-INF/resin-web.xml"><web-app xmlns="http://caucho.com/ns/resin"> <servlet> <servlet-name>cgi</servlet-name> <servlet-class>com.caucho.servlets.CGIServlet</servlet-class> </servlet> <servlet-mapping servlet-name="cgi" url-pattern="/cgi-bin/*.exe"/></web-app></example><p>The <code>servlet-mapping</code> specifies the requests that will be treated asCGI exectutables. In the example above, only files in the /cgi-bin directorywith an extension of ".exe" will be executed. It is important to limit theurl-pattern as much as possible to avoid allowing unintended execution ofscripts or binaries on the system.</p><p>A CGI script must output a blank line between the HTTP header(s) and therest of the response. If no blank line is encountered, the contents of yourbrowser page will be blank. Usually a CGI script will output a<code>Content-Type:</code> header and then a blank line before the content:</p><example title="Minimal CGI script">#!/bin/shecho "Content-Type: text/html"echoecho "<h>CGI Test<h1>"echo "CGI Test"echo "<pre>"envecho "</pre>"</example></s1><s1 title="DirectoryServlet"><p>The directory servlet provides the basic directory browsing.The servlet-name must be "directory" for the servlet to take effect.Sites will normally disable it.</p><deftable-parameters><tr> <td>enable</td> <td>Enable or disable the servlet</td> <td>true</td></tr></deftable-parameters><example><servlet servlet-name="directory" servlet-class="com.caucho.servlets.DirectoryServlet"> <init enable="false"/></servlet></example></s1><s1 title="FastCGIServlet"><p>Implements the FastCGI protocol. FastCGI allows some CGI clientslike PHP to run quicker and more efficiently.</p><deftable-parameters><tr><td>server-address</td><td>the host and port number, in the form host:port</td><td>required</td></tr></deftable-parameters><p>The FastCGIServlet creates a socket connection from Resin to the backendprogram that supports the fastcgi protocol. <a config-tag="servlet-mapping"/>is used to configure the filename patterns of scripts that are handled by thebackend program.</p><p>The following example configures Resin so that any files within a single webappmatching the pattern"*.php" are handled by the backend program:</p><example title="WEB-INF/web.xml"><web-app> <servlet> <servlet-name>php-fastcgi</servlet-name> <servlet-class>com.caucho.servlets.FastCGIServlet</servlet-class> <init> <server-address>localhost:6666</server-address> </init> </servlet> <servlet-mapping> <servlet-name>php-fastcgi</servlet-name> <url-pattern>*.php</url-pattern> </servlet-mapping></web-app></example><p>Assuming PHP has been compiled with -fastcgi enabled, you mightstart PHP like:</p><example>unix> php -b 6666 </example><p>Mapping is enabled for all web-apps with the use of <a config-tag="web-app-default"/>. In this example, filenames with the pattern"*.php" and the pattern "*.phtml" are handled by the backend program: </p><example title="resin.xml"><web-app-default> <servlet> <servlet-name>php-fastcgi</servlet-name> <servlet-class>com.caucho.servlets.FastCGIServlet</servlet-class> <init> <server-address>localhost:6666</server-address> </init> </servlet> <servlet-mapping url-pattern="*.php" servlet-name="php-fastcgi"/> <servlet-mapping url-pattern="*.phtml" servlet-name="php-fastcgi"/></web-app></example><p>See <a href="javadoc|com.caucho.servlets.FastCGIServlet|"/>.</p></s1><s1 title="HttpProxyServlet"><p><a href="javadoc|com.caucho.servlets.HttpProxyServlet|"/> is a servlet thatproxies to another server. This can be useful for providing access to legacybackend servers.</p><example title="HttpProxyServlet"> <servlet> <servlet-name>http-proxy</servlet-name> <servlet-class>com.caucho.servlets.HttpProxyServlet</servlet-class> <init host='localhost:8081'/> </servlet> <servlet-mapping url-pattern="/foo/*" servlet-name="http-proxy"/> <servlet-mapping url-pattern="/bar/*" servlet-name="http-proxy"/></example><p>There is a bit more power using servlet-regexp and regular expressions:</p><example title="HttpProxyServlet with regexp"><servlet-regexp url-regexp="^/foo(/.*)?" servlet-class="com.caucho.servlets.HttpProxyServlet"> <init host='localhost:8081'/></servlet-regexp></example></s1><s1 title="SSIServlet"><p><a href="javadoc|com.caucho.servlets.ssi.SSIServlet|"/> is a servlet thatprocesses server side include directives. The syntax for server side includesis the same as the syntax used in <a href="http://httpd.apache.org/docs/1.3/mod/mod_include.html">Apache httpd</a>.</p><example title="resin-web.xml SSIServlet"><web-app xmlns="http://caucho.com/ns/resin"> <servlet-mapping url-pattern="*.shtml" servlet-class="com.caucho.servlets.ssi.SSIServlet"/></web-app></example><example title="test.shtml"><h1>A little test</h1><!--#config timefmt="%Y-%m-%d" --><!--#echo var="DATE_GMT" --><!--#include virtual="inc.jsp" --><!--#set var="a" value="$REQUEST_METHOD" --><!--#include virtual="inc.jsp?q=$a" --></example></s1><s1 title="WebDAVServlet"><p>WebDAV, web-based distributed authoring and versioning, is a setof extensions to the HTTP protocol that is a convenient replacementfor FTP when developing web sites. Many editing tools can save to aWebDAV server directly and several operating systems can provide afilesystem to a WebDAV server.</p><p>From <a href="http://www.webdav.org">www.webdav.org</a>:</p><blockquote><b>What is WebDAV?</b><br/>Briefly: WebDAV stands for "Web-based Distributed Authoring and Versioning".It is a set of extensions to the HTTP protocol which allows users tocollaboratively edit and manage files on remote web servers.</blockquote><p>The WebDAV site also contains pointers to programs whichunderstand WebDAV.</p><p>The WebDAV servlet must be enabled explicitly. By default, it alsorequires a logged in user playing the 'webdav' role and requires asecure (SSL) connection. These can be relaxed, but havingthe defaults require security makes it unlikely that a webmaster willenable WebDAV by mistake.</p><deftable-parameters><tr><td>enable</td><td>Enable webdav servlet for read ("read") or read/write ("write")</td><td>false (disabled)</td></tr><tr><td>role</td><td>The role required for webdav, '*' means no role required</td><td>webdav</td></tr><tr><td>user</td><td>A specific user required for webdav</td><td>none</td></tr><tr><td>secure</td><td>If true, only allow updates over a secure connection(SSL)</td><td>true</td></tr><tr><td>root</td><td>Configures the root directory for webdav</td><td>The application root</td></tr><tr><td>path-source</td><td>The jndi name of a custom path backing previously defined as a resource. This allows a custom path backing, e.g. a database source</td><td>an instance of <a href="javadoc|com.caucho.servlets.webdav.ApplicationPath|"/></td></tr></deftable-parameters><p>The following example is a typical WebDAV configuration. The explicitservlet-mapping and setting <var>enable</var> to 'write' is necessary. Since<var>secure</var> is left as the default, it will require an SSL connection.</p><example title="Enabling WebDAV"><servlet> <servlet-name>webdav</servlet-name> <servlet-class>com.caucho.servlets.webdav.WebDavServlet</servlet-class> <init> <enable>write</enable> </init></servlet><servlet-mapping url-pattern='/webdav/*' servlet-name='webdav'/><authenticator> <type>com.caucho.server.security.XmlAuthenticator</type> <init> <user>Harry Potter:quidditch:webdav</user> <password-digest>none</password-digest> </init></authenticator><login-config> <auth-method>basic</auth-method></login-config><security-constraint url-pattern='/webdav/*' role-name='webdav'/></example><p>The following example is not recommended because it would allow anyone toupdate the site:</p><example title="WebDAV with no security"><servlet> <servlet-name>webdav</servlet-name> <servlet-class>com.caucho.servlets.webdav.WebDavServlet</servlet-class> <init> <enable>write</enable> <secure>false</secure> <role>*</role> </init></servlet><servlet-mapping url-pattern='/webdav/*' servlet-name='webdav'/></example><p>The WebDAV servlet can point to a different directory bysetting the <var>root</var> parameter. The path is relative to theweb-app, and allows path variables. For example, the following wouldread and write files from WEB-INF/webdav:</p><example title="WebDAV based on WEB-INF/webdav"><servlet> <servlet-name>webdav</servlet-name> <servlet-class>com.caucho.servlets.webdav.WebDavServlet</servlet-class> <init> <root>WEB-INF/webdav</root> <enable>write</enable> <role>webdav</role> </init></servlet><servlet-mapping url-pattern='/webdav/*' servlet-name='webdav'/></example><s2 title="Configuring Windows"><p>Recent versions of Windows and the Windows Office suite directlysupport WebDAV. WebDAV is configured in "My Network Places".</p><p>When browsing "My Network Places" in IE, click on Tools/Map NetworkDrive from the menu. IE will open a dialog. The dialog contains alink to "Create a shortcut to Web folder or FTP site". Clicking onthat will open the "Add Network Place Wizard".</p><p>The Add Network Place Wizard will ask for the location of theWebDAV server. Type the full URL, e.g. http://www.foo.com/webdav andcomplete the dialog.</p><p>Adding the WebDAV link will let you save directly to your server.Windows programs can load and save to the server. You can also open anIE window to the mapped folder and use it as a normal folder.</p></s2><s2 name="customize" title="Custom Path Sources"><p>The WebDAV servlet can be customized to use a source other than thedefault path source. For example, it would be possible to use WebDAVwith files stored in a database.</p><p>There's a <code><path-source>java:comp/env/my-path</path-source></code> parameter in the WebDavServlet(see <a href="#configure">Configuring theWebDAV Servlet</a>). You configure an object with the JNDI name<code>java:comp/env/my-path</code> using <a config-tag="resource"/> toconfigure a custom class that extends <a href="javadoc|com.caucho.servlets.webdav.AbstractPath|"/></p><example title="WebDAV with a custom source"><resource jndi-name='resin/webdav'> <type>test.foo.MyDataSource</type> <init> <my-foo>bar</my-foo> </init></resource><servlet> <servlet-name>webdav</servlet-name> <servlet-class>com.caucho.servlets.webdav.WebDavServlet</servlet-class> <init> <enable>write</enable> <path-source>resin/webdav</path-source> </init></servlet><servlet-mapping url-pattern='/webdav/*' servlet-name='webdav'/></example><p>You can completely customize your WebDav backend, linking it to databases or some EJB-based data source or whatever.</p></s2><s2 title="Configuring the WebDAV servlet to recognize more than one root folder?" type="faq"> <p>There's a "root" parameter for the WebDavServlet (see <a href="#configure">Configuring the WebDAV Servlet</a>). You canset that and use several separate webdav instances.</p><example><servlet> <servlet-name>webdav1</servlet-name> <servlet-class>com.caucho.servlets.webdav.WebDavServlet</servlet-class> <init> <root>/opt/root1</root> </init></servlet><servlet> <servlet-name>webdav2</servlet-name> <servlet-class>com.caucho.servlets.webdav.WebDavServlet</servlet-class> <init> <root>/opt/root1</root> </init></servlet><servlet-mapping url-pattern='/root1' servlet-name='webdav1'/><servlet-mapping url-pattern='/root2' servlet-name='webdav2'/></example></s2><s2 title="Making the root path match a user name?" type="faq"><p>What if one wants to make the root user-dependant? i.e. have user "ferg"have the root in "/somefolder/ferg" and user "jeff" have the root in"/somefolder/jeff"</p><p>It's possible, but you need to write a bit of code.</p><p>As discussed in <a href="#customize">Custom Path Sources</a>, youcan customize the data source by creating your own ApplicationPath.</p><p>In this case, you probably want to extend <a href="javadoc|com.caucho.servlets.webdav.FilePath|"/> and override the getPath method.</p></s2></s1><s1 title="run-at"><p>The "run-at" capability should now be configured using the<a href="resources.xtp"><scheduled-task></a> capability.</p></s1> </body></document>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -