|
Now a days the complex application are always bigger in size. So the number of action mappings will also increases. Wildcards can be used to combine similar mappings into one more generic mapping and helps to reduce the size of the config files.
Wildcard patterns can contain one or more of the following special tokens:
*
|
Matches zero or more characters excluding the slash ('/') character.
|
**
|
Matches zero or more characters including the slash ('/') character.
|
\character
|
The backslash character is used as an escape sequence. Thus \* matches the character asterisk ('*'), and \\ matches the character backslash ('\').
|
Note :-In the action mapping and action forwards, the wildcard-matched values can be accessed with the token {N} where N is a number from 1 to 9 indicating which wildcard-matched value to substitute. The whole request URI can be accessed with the {0} token.
The action mapping attributes that will accept wildcard-matched strings are:
- attribute
- catalog
- command
- forward
- include
- input
- multipartClass
- name
- parameter
- prefix
- roles
- suffix
- type
The action forward attributes that will accept wildcard-matched strings are:
The below example will demonstrate the Use of wildcard characters.
(1) Struts-config.xml
Note:- In the action mapping the parameter is passed as {1}. The jsp which invoked the action replaces the parameter with the name ofthe jsp in all places.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <!-- ================================================ Form Bean Definitions --> <form-beans> <form-bean name="InputForm" type="com.visualbuilder.InputForm" />
<form-bean name="RegisterForm" type="com.visualbuilder.RegisterForm"/>
</form-beans> <!-- ========================================= Global Exception Definitions --> <global-exceptions></global-exceptions> <!-- =========================================== Global Forward Definitions --> <global-forwards></global-forwards> <!-- =========================================== Action Mapping Definitions --> <action-mappings>
<action path="/submit*" type="com.visualbuilder.Submit{1}Action" name="{1}Form" scope="request" validate="false" input="/{1}.jsp"/>
</action-mappings>
<!-- ======================================== Message Resources Definitions --> <message-resources parameter="MessageResources" />
</struts-config> |