<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"> | |
<HTML> | |
<HEAD> | |
<meta name="generator" content="JDiff v1.1.1"> | |
<!-- Generated by the JDiff Javadoc doclet --> | |
<!-- (http://www.jdiff.org) --> | |
<meta name="description" content="JDiff is a Javadoc doclet which generates an HTML report of all the packages, classes, constructors, methods, and fields which have been removed, added or changed in any way, including their documentation, when two APIs are compared."> | |
<meta name="keywords" content="diff, jdiff, javadiff, java diff, java difference, API difference, difference between two APIs, API diff, Javadoc, doclet"> | |
<LINK REL="stylesheet" TYPE="text/css" HREF="../stylesheet-jdiff.css" TITLE="Style"> | |
<TITLE> | |
com.google.inject.servlet Documentation Differences | |
</TITLE> | |
</HEAD> | |
<BODY> | |
<!-- Start of nav bar --> | |
<TABLE summary="Navigation bar" BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"> | |
<TR> | |
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> | |
<TABLE summary="Navigation bar" BORDER="0" CELLPADDING="0" CELLSPACING="3"> | |
<TR ALIGN="center" VALIGN="top"> | |
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="http://google-guice.googlecode.com/svn/trunk/latest-api-diffs/3.0/javadoc/com/google/inject/servlet/package-summary.html" target="_top"><FONT CLASS="NavBarFont1"><B><tt>3.0</tt></B></FONT></A> </TD> | |
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="changes-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> | |
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Package</FONT> </TD> | |
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT> </TD> | |
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="docdiffs_index.html"><FONT CLASS="NavBarFont1"><B>Text Changes</B></FONT></A> </TD> | |
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="jdiff_statistics.html"><FONT CLASS="NavBarFont1"><B>Statistics</B></FONT></A> </TD> | |
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="jdiff_help.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> | |
</TR> | |
</TABLE> | |
</TD> | |
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Generated by<br><a href="http://www.jdiff.org" class="staysblack" target="_top">JDiff</a></b></EM></TD> | |
</TR> | |
<TR> | |
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell2"><FONT SIZE="-2"> | |
<A HREF="docdiffs_com.google.inject.multibindings.html"><B>PREV PACKAGE</B></A> | |
<A HREF="docdiffs_com.google.inject.spi.html"><B>NEXT PACKAGE</B></A> | |
| |
<A HREF="../changes.html" TARGET="_top"><B>FRAMES</B></A> | |
<A HREF="docdiffs_com.google.inject.servlet.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD> | |
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell2"> </TD> | |
</TR> | |
</TABLE> | |
<HR> | |
<!-- End of nav bar --> | |
<h2> | |
com.google.inject.servlet Documentation Differences | |
</h2> | |
<blockquote> | |
This file contains all the changes in documentation in the package <code>com.google.inject.servlet</code> as colored differences. | |
Deletions are shown <strike>like this</strike>, and | |
additions are shown <span style="background: #FFFF00">like this</span>. | |
</blockquote> | |
<blockquote> | |
If no deletions or additions are shown in an entry, the HTML tags will be what has changed. The <i>new</i> HTML tags are shown in the differences. | |
If no documentation existed, and then some was added in a later version, this change is noted in the appropriate class pages of differences, but the change is not shown on this page. Only changes in existing text are shown here. | |
Similarly, documentation which was inherited from another class or interface is not shown here. | |
</blockquote> | |
<blockquote> | |
Note that an HTML error in the new documentation may cause the display of other documentation changes to be presented incorrectly. For instance, failure to close a <code> tag will cause all subsequent paragraphs to be displayed differently. | |
</blockquote> | |
<hr> | |
<A NAME="com.google.inject.servlet.ServletModule.dmethod.configureServlets()"></A><a href="com.google.inject.servlet.ServletModule.html" class="hiddenlink">Class <b>ServletModule</b></a>, <a href="com.google.inject.servlet.ServletModule.html#com.google.inject.servlet.ServletModule.configureServlets_changed()" class="hiddenlink">void <b>configureServlets()</b></a><br><br><blockquote><h3>Servlet Mapping EDSL</h3> | |
<p> Part of the EDSL builder language for configuring servlets | |
and filters with guice-servlet. Think of this as an in-code replacement for web.xml. | |
Filters and servlets are configured here using simple java method calls. Here is a typical | |
example of registering a filter when creating your Guice injector: | |
<pre> | |
Guice.createInjector(..., new ServletModule() { | |
{@literal @}Override | |
protected void configureServlets() { | |
<b>serve("*.html").with(MyServlet.class)</b> | |
} | |
} | |
</pre> | |
This registers a servlet (subclass of {@code HttpServlet}) called {@code MyServlet} to service | |
any web pages ending in {@code .html}. You can also use a path-style syntax to register | |
servlets: | |
<pre> | |
<b>serve("/my/*").with(MyServlet.class)</b> | |
</pre> | |
Every servlet (or filter) is required to be a singleton. If you cannot annotate the class | |
directly, you should add a separate {@code bind(..).in(Singleton.class)} rule elsewhere in | |
your module. Mapping a servlet that is bound under any other scope is an error. | |
<p> | |
<h4>Dispatch Order</h4> | |
You are free to register as many servlets and filters as you like this way. They will | |
be compared and dispatched in the order in which the filter methods are called: | |
<pre> | |
Guice.createInjector(..., new ServletModule() { | |
{@literal @}Override | |
protected void configureServlets() { | |
filter("/*").through(MyFilter.class); | |
filter("*.css").through(MyCssFilter.class); | |
<span style="background: #FFFF00">filter("*.jpg").through(new MyJpgFilter()); | |
</span>// etc.. | |
serve("*.html").with(MyServlet.class); | |
serve("/my/*").with(MyServlet.class); | |
<span style="background: #FFFF00">serve("*.jpg").with(new MyServlet()); | |
</span>// etc.. | |
} | |
} | |
</pre> | |
This will traverse down the list of rules in lexical order. For example, a url | |
"{@code /my/file.js}" (after it runs through the matching filters) will first | |
be compared against the servlet mapping: | |
<pre> | |
serve("*.html").with(MyServlet.class); | |
</pre> | |
And failing that, it will descend to the next servlet mapping: | |
<pre> | |
serve("/my/*").with(MyServlet.class); | |
</pre> | |
Since this rule matches, Guice Servlet will dispatch to {@code MyServlet}. These | |
two mapping rules can also be written in more compact form using varargs syntax: | |
<pre> | |
serve(<b>"*.html", "/my/*"</b>).with(MyServlet.class); | |
</pre> | |
This way you can map several URI patterns to the same servlet. A similar syntax is | |
also available for filter mappings. | |
<p> | |
<h4>Regular Expressions</h4> | |
You can also map servlets (or filters) to URIs using regular expressions: | |
<pre> | |
<b>serveRegex("(.)*ajax(.)*").with(MyAjaxServlet.class)</b> | |
</pre> | |
This will map any URI containing the text "ajax" in it to {@code MyAjaxServlet}. Such as: | |
<ul> | |
<li>http://www.google.com/ajax.html</li> | |
<li>http://www.google.com/content/ajax/index</li> | |
<li>http://www.google.com/it/is_totally_ajaxian</li> | |
</ul> | |
<h3>Initialization Parameters</h3> | |
Servlets (and filters) allow you to pass in init params | |
using the {@code <init-param>} tag in web.xml. You can similarly pass in parameters to | |
Servlets and filters registered in Guice-servlet using a <A HREF="http://google-guice.googlecode.com/svn/trunk/latest-api-diffs/3.0/javadoc/java/util/Map.html"><TT>java.util.Map</TT></A> of parameter | |
name/value pairs. For example, to initialize {@code MyServlet} with two parameters | |
({@code name="Dhanji", site="google.com"}) you could write: | |
<pre> | |
Map<String, String> params = new HashMap<String, String>(); | |
params.put("name", "Dhanji"); | |
params.put("site", "google.com"); | |
... | |
serve("/*").with(MyServlet.class, <b>params</b>) | |
</pre> | |
<p> | |
<h3>Binding Keys</h3> | |
You can also bind keys rather than classes. This lets you hide | |
implementations with package-local visbility and expose them using | |
only a Guice module and an annotation: | |
<pre> | |
... | |
filter("/*").through(<b>Key.get(Filter.class, Fave.class)</b>); | |
</pre> | |
Where {@code Filter.class} refers to the Servlet API interface and {@code Fave.class} is a | |
custom binding annotation. Elsewhere (in one of your own modules) you can bind this | |
filter's implementation: | |
<pre> | |
bind(Filter.class)<b>.annotatedWith(Fave.class)</b>.to(MyFilterImpl.class); | |
</pre> | |
See <A HREF="http://google-guice.googlecode.com/svn/trunk/latest-api-diffs/3.0/javadoc/com/google/inject/Binder.html"><TT>com.google.inject.Binder</TT></A> for more information on binding syntax. | |
<p> | |
<h3>Multiple Modules</h3> | |
It is sometimes useful to capture servlet and filter mappings from multiple different | |
modules. This is essential if you want to package and offer drop-in Guice plugins that | |
provide servlet functionality. | |
<p> | |
Guice Servlet allows you to register several instances of {@code ServletModule} to your | |
injector. The order in which these modules are installed determines the dispatch order | |
of filters and the precedence order of servlets. For example, if you had two servlet modules, | |
{@code RpcModule} and {@code WebServiceModule} and they each contained a filter that mapped | |
to the same URI pattern, {@code "/*"}: | |
<p> | |
In {@code RpcModule}: | |
<pre> | |
filter("/*").through(RpcFilter.class); | |
</pre> | |
In {@code WebServiceModule}: | |
<pre> | |
filter("/*").through(WebServiceFilter.class); | |
</pre> | |
Then the order in which these filters are dispatched is determined by the order in which | |
the modules are installed: | |
<pre> | |
<b>install(new WebServiceModule());</b> | |
install(new RpcModule()); | |
</pre> | |
In the case shown above {@code WebServiceFilter} will run first. | |
@since 2.0</blockquote> | |
<hr align="left" width="100%"> | |
</BODY> | |
</HTML> |