| java.lang.Object org.apache.struts.action.Action org.apache.struts.scripting.ScriptAction
ScriptAction | public class ScriptAction extends Action (Code) | | This Action uses scripts to perform its action. The scripting framework is
Apache's Bean Scripting Framework which allows the scripts to be written
many of the popular scripting languages including JavaScript, Perl, Python,
and even VBA.
To determine what script will be executed, the "parameter" attribute of the
action mapping should contain the name of the script relative to the web
application root directory (i.e. http://server/app).
Before the script completes, the next ActionForward needs to be specified.
This can be done one of two ways:
- Set
struts.forwardName to the name of the forward
- Set
struts.forward to the actual ActionForward object
A number of pre-defined variables are available to the script:
-
request - The HTTP request
-
response - The HTTP response
-
session - The session
-
application - The servlet context
-
struts - A grouping of all Struts-related objects
-
log - A logging instance
You can add your own variables by creating a BSFManagerFilter and
configuring it in struts-scripting.properties:
-
struts-scripting.filters.FILTER_NAME.class=FILTER_CLASS
- The class implementing BSFManagerFilter where FILTER_NAME is the name
you are calling the filter.
-
struts-scripting.filters.FILTER_NAME.PROPERTY_NAME=PROPERTY_VALUE
- A property to be used by the filter.
To use other scripting engines other than BeanShell, create a file called
struts-scripting.properties and add two properties for each
engine:
-
struts-scripting.engine.ENGINE_NAME.class - The class of
the BSF engine where ENGINE_NAME is the name you are calling the engine.
-
struts-scripting.engine.ENGINE_NAME.extensions - A
comma-delimited list of file extensions that will be used to identify the
engine to use to execute the script.
This code was originally based off code from JPublish, but has since been
almost completely rewritten.
|
Inner Class :class Script | |
Field Summary | |
final protected static String | ENGINE_BASE The base property for alternate BSF engines. | final protected static String | FILTERS_BASE The base property for classes that put new variables in the context. | final protected static Log | LOG The logging instance. | final protected static String | PROPS_PATH The default path to the properties file. |
ENGINE_BASE | final protected static String ENGINE_BASE(Code) | | The base property for alternate BSF engines.
|
FILTERS_BASE | final protected static String FILTERS_BASE(Code) | | The base property for classes that put new variables in the context.
|
LOG | final protected static Log LOG(Code) | | The logging instance.
|
PROPS_PATH | final protected static String PROPS_PATH(Code) | | The default path to the properties file.
|
isCancelled | public boolean isCancelled(HttpServletRequest req)(Code) | | Checks to see if the request is cancelled.
Parameters: req - The request object True if cancelled |
isTokenValid | public boolean isTokenValid(HttpServletRequest req)(Code) | | Checks to see if the token is valid.
Parameters: req - The request object True if valid |
loadFilters | protected static BSFManagerFilter[] loadFilters(Properties props)(Code) | | Loads and initializes the filters.
Parameters: props - The properties defining the filters An array of the loaded filters |
loadScript | protected Script loadScript(String name, ServletContext context)(Code) | | Loads the script from cache if possible. Reloads if the script has been
recently modified.
Parameters: name - The name of the script Parameters: context - The servlet context The script object |
parseScriptName | protected String parseScriptName(String url, BSFManager manager) throws Exception(Code) | | Parses the script name and puts any url parameters in the context.
Parameters: url - The script url consisting of a path and optionalparameters Parameters: manager - The BSF manager to declare new parameters in The name of the script to execute exception: Exception - If something goes wrong |
saveErrors | public void saveErrors(HttpServletRequest req, ActionErrors errs)(Code) | | Saves the errors to the request.
Parameters: req - The request object Parameters: errs - The action errors |
saveMessages | public void saveMessages(HttpServletRequest req, ActionMessages mes)(Code) | | Saves the messages to the request.
Parameters: req - The request object Parameters: mes - The action messages |
split | protected static String[] split(String line, String delimiter)(Code) | | Splits a line with the given delimiter.
Parameters: line - The line to split Parameters: delimiter - The string to split with An array of substrings |
Methods inherited from org.apache.struts.action.Action | protected void addErrors(HttpServletRequest request, ActionMessages errors)(Code)(Java Doc) protected void addMessages(HttpServletRequest request, ActionMessages messages)(Code)(Java Doc) public ActionForward execute(ActionMapping mapping, ActionForm form, ServletRequest request, ServletResponse response) throws Exception(Code)(Java Doc) public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception(Code)(Java Doc) protected String generateToken(HttpServletRequest request)(Code)(Java Doc) protected ActionMessages getErrors(HttpServletRequest request)(Code)(Java Doc) protected Locale getLocale(HttpServletRequest request)(Code)(Java Doc) protected ActionMessages getMessages(HttpServletRequest request)(Code)(Java Doc) protected MessageResources getResources(HttpServletRequest request)(Code)(Java Doc) protected MessageResources getResources(HttpServletRequest request, String key)(Code)(Java Doc) public ActionServlet getServlet()(Code)(Java Doc) protected boolean isCancelled(HttpServletRequest request)(Code)(Java Doc) protected boolean isTokenValid(HttpServletRequest request)(Code)(Java Doc) protected boolean isTokenValid(HttpServletRequest request, boolean reset)(Code)(Java Doc) protected void resetToken(HttpServletRequest request)(Code)(Java Doc) protected void saveErrors(HttpServletRequest request, ActionMessages errors)(Code)(Java Doc) protected void saveErrors(HttpSession session, ActionMessages errors)(Code)(Java Doc) protected void saveMessages(HttpServletRequest request, ActionMessages messages)(Code)(Java Doc) protected void saveMessages(HttpSession session, ActionMessages messages)(Code)(Java Doc) protected void saveToken(HttpServletRequest request)(Code)(Java Doc) protected void setLocale(HttpServletRequest request, Locale locale)(Code)(Java Doc) public void setServlet(ActionServlet servlet)(Code)(Java Doc)
|
|
|