SWF-1411 SWF-1409 Documentation fixes

This commit is contained in:
Rossen Stoyanchev
2010-10-28 13:44:57 +00:00
parent d2e45a8582
commit 21d314b9b8
3 changed files with 90 additions and 6 deletions

View File

@@ -17,7 +17,8 @@
<sect1 id="spring-js-resource-servlet">
<title>Serving Javascript Resources</title>
<para>
Spring JS provides a generic <code>ResourceServlet</code> to serve web resources such as JavaScript and CSS files from jar files, as well as the webapp root directory.
Spring JS provides a generic <code>ResourceServlet</code> to serve web resources such as JavaScript and CSS files from jar files,
as well as the webapp root directory.
This servlet provides a convenient way to serve Spring.js files to your pages.
To deploy this servlet, declare the following in <code>web.xml</code>:
</para>
@@ -34,7 +35,80 @@
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>]]>
</programlisting>
</sect1>
<para>
Note that starting with version 3.0.4, the Spring Framework includes
a replacement for the <code>ResourceServlet</code> (see the
<ulink url="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-static-resources">Spring Framework documentation</ulink>).
With the new &lt;mvc:resources&gt; element resource requests (.js, .css) are handled by the
<code>DispatcherSevlet</code> without the need for a separate <code>ResourceServlet</code>.
Here is the relevant portion of the Spring MVC configuration in
the mvc-booking sample:
</para>
<programlisting language="xml"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/" />
...
</beans>
]]>
</programlisting>
<para>
This incoming maps requests for <code>/resources</code> to resources found under
<code>/META-INF/web-resources</code> on the classpath. That's where Spring JavaScript resources
are bundled. However, you can modify the location attribute in the above configuration in order
to serve resources from any classpath or web application relative location.
</para>
<para>
Note that the full resource URL depends on how your DispatcherServlet is mapped.
In the mvc-booking sample we've chosen to map it with the default servlet mapping '/':
</para>
<programlisting language="xml"><![CDATA[
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
]]>
</programlisting>
<para>
That means the full URL to load <code>Spring.js</code> is <code>/myapp/resources/spring/Spring.js</code>.
If your <code>DispatcherServlet</code> was instead mapped to <code>/main/*</code> then the full
URL would be <code>/myapp/main/resources/spring/Spring.js</code>.
</para>
<para>
When using of the default servlet mapping it is also recommended to add this to your Spring MVC
configuration, which ensures that any resource requests not handled by your Spring MVC mappings
will be delegated back to the Servlet container.
</para>
<programlisting language="xml"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
...
<mvc:default-servlet-handler />
</beans>
]]>
</programlisting>
</sect1>
<sect1 id="spring-js-includes">
<title>Including Spring Javascript in a Page</title>
<para>