You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2023/10/10 13:19:45 UTC
[struts-site] 01/01: Extends description how static content is supported
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch fix/static-content-mapping
in repository https://gitbox.apache.org/repos/asf/struts-site.git
commit 1a44d87cfefabf0abdbb380cf5d6580969e2a475
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Tue Oct 10 15:19:38 2023 +0200
Extends description how static content is supported
---
source/core-developers/static-content.md | 15 +++++---
source/core-developers/web-xml.md | 60 +++++++++++++++++++-------------
2 files changed, 47 insertions(+), 28 deletions(-)
diff --git a/source/core-developers/static-content.md b/source/core-developers/static-content.md
index 6e5899359..0967b289a 100644
--- a/source/core-developers/static-content.md
+++ b/source/core-developers/static-content.md
@@ -9,15 +9,22 @@ title: Static Content
* Will be replaced with the ToC, excluding a header
{:toc}
-Struts can serve static content like css and javascript files. This feature is enabled by default, but can be disabled
-by setting:
+Struts can serve a static content like CSS and JavaScript files using a predefined path. By default, these resources
+are served using `/static` path defined using a constant `struts.ui.staticContentPath` - see below for more details.
+
+Please remember to include this path in your filter mapping if you use a custom mapping, see [web.xml](web-xml.md) example config.
+
+## Disabling static content
+
+You can disable this feature by setting the following constant to `false`. Once disabled you must provided the required
+CSS & JavaScript files on your own, which can be a good thing when you want to use a CDN.
```xml
<constant name="struts.serve.static" value="false"/>
```
-> If you disable this feature, but use the `xhtml`, or `css_xhtml` theme, make sure that the javascript and css files
-> shipped inside the core jar are extracted to your web application directory.
+> If you disable this feature, but you use the `xhtml`, or `css_xhtml` theme, make sure the JavasScript and CSS files
+> shipped inside the core jar are extracted to your web application directory or served in some other way.
## Custom Static Content Loaders
diff --git a/source/core-developers/web-xml.md b/source/core-developers/web-xml.md
index b8aca95af..5e947b663 100644
--- a/source/core-developers/web-xml.md
+++ b/source/core-developers/web-xml.md
@@ -43,40 +43,52 @@ Configuring `web.xml` for the framework is a matter of adding a filter and filte
</web-app>
```
-## Changed filter package in Struts >= 2.5
+See [SiteMesh Plugin](../plugins/sitemesh-plugin) for an example on when to use separate Filters for prepare and execution phase.
-As from Struts 2.5 all filters were moved to top package, if you are using older version you must use the old package,
-see example:
+## Custom mapping
+
+The above approach is a preferred way of enabling support for Struts in your web application. Yet you can have more
+specific requirements and use more specific mapping like presented below:
```xml
-<web-app id="WebApp_9" version="2.4"
- xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+<web-app ...>
<filter>
<filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
- ...
+
+ <filter-mapping>
+ <filter-name>struts2</filter-name>
+ <url-pattern>*.action</url-pattern>
+ </filter-mapping>
+
</web-app>
```
-## Changed Filter Structure in Struts >= 2.1.3
-
-To split up the the dispatcher phases, FilterDispatcher is deprecated since Struts 2.1.3. If working with older
-versions, you need to use
+In such case only requests ending with `.action` will be directed by a Servlet container to be handled by Struts filter.
+This can impact serving static content provided by Struts and you will have to define additional mapping to support it:
```xml
- ...
+<web-app ...>
+
<filter>
<filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
- ...
-```
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
+ </filter>
-See [SiteMesh Plugin](../plugins/sitemesh-plugin) for an example on when to use separate Filters for prepare
-and execution phase.
+ <filter-mapping>
+ <filter-name>struts2</filter-name>
+ <url-pattern>*.action</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>struts2</filter-name>
+ <url-pattern>/static/*</url-pattern>
+ </filter-mapping>
+
+</web-app>
+```
## Exclude specific URLs
@@ -110,8 +122,8 @@ the container will discover it automatically.
`META-INF` folder, and add a `taglib` element to the `web.xml`.
```xml
- <!-- ... -->
- </welcome-file-list>
+<web-app ...>
+ <!-- ... -->
<taglib>
<taglib-uri>/s</taglib-uri>
@@ -155,8 +167,8 @@ Take a look on default implementations - `DefaultFileManager.java` and `DefaultF
## Custom configuration provider
-It is possible to use your custom `ConfigurationProvider` to programmatically configure your application. To do this use
-`configProviders` (it can be a comma-separated list of class names) `<init-param/>` as below:
+It is possible to use your custom `ConfigurationProvider` to programmatically configure your application. To do this use
+`configProviders` (it can be a comma-separated list of class names) `<init-param/>` as below:
```xml
<filter>
@@ -169,4 +181,4 @@ It is possible to use your custom `ConfigurationProvider` to programmatically c
</filter>
```
-See [Configuration Provider & Configuration](configuration-provider-and-configuration) for more details.
+See [Configuration Provider & Configuration](configuration-provider-and-configuration) for more details.