Class ScriptAction
- All Implemented Interfaces:
Serializable
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. https://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 ScriptContextFilter
and configuring it in struts-scripting.properties:
struts-scripting.filters.FILTER_NAME.class=FILTER_CLASS
- The class implementingScriptContextFilter
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, add them to the classpath.
To register more extensions to a scripting engine, create a file called
struts-scripting.properties
and add one propertie for each
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.
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionexecute
(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) Executes the script.Gets the locale.boolean
Checks to see if the request is cancelled.boolean
Checks to see if the token is valid.protected static ScriptContextFilter[]
loadFilters
(Properties props) Loads and initializes the filters.protected org.apache.struts.scripting.Script
loadScript
(String name, ServletContext context) Loads the script from cache if possible.protected String
parseScriptName
(String url, Map<String, String> params) Parses the script name and puts any URL parameters in the context.void
Resets the token.void
saveErrors
(HttpServletRequest req, ActionErrors errs) Deprecated.Use saveErrors(HttpServletRequest, ActionMessages) instead.void
saveMessages
(HttpServletRequest req, ActionMessages mes) Saves the messages to the request.void
Saves a token.Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getErrors, getMessages, getResources, getResources, getServlet, isTokenValid, saveErrors, saveErrors, saveMessages, setLocale, setServlet
-
Field Details
-
PROPS_PATH
The default path to the properties file.- See Also:
-
ENGINE_BASE
The base property for alternate BSF engines.- See Also:
-
FILTERS_BASE
The base property for classes that put new variables in the context.- See Also:
-
-
Constructor Details
-
ScriptAction
public ScriptAction()
-
-
Method Details
-
execute
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception Executes the script. -
parseScriptName
Parses the script name and puts any URL parameters in the context.- Parameters:
url
- The script URL consisting of a path and optional parametersparams
- A parameter-map to declare new parameters in- Returns:
- The name of the script to execute
-
loadScript
protected org.apache.struts.scripting.Script loadScript(String name, ServletContext context) throws IOException, ScriptException Loads the script from cache if possible. Reloads if the script has been recently modified.- Parameters:
name
- The name of the scriptcontext
- The servlet context- Returns:
- The script object
- Throws:
IOException
- if an I/O error occursScriptException
- if compilation fails
-
loadFilters
Loads and initializes the filters.- Parameters:
props
- The properties defining the filters- Returns:
- An array of the loaded filters
-
saveToken
Saves a token. -
isCancelled
Checks to see if the request is cancelled.- Overrides:
isCancelled
in classAction
- Parameters:
req
- The request object- Returns:
- True if cancelled
-
isTokenValid
Checks to see if the token is valid.- Overrides:
isTokenValid
in classAction
- Parameters:
req
- The request object- Returns:
- True if valid
-
resetToken
Resets the token.- Overrides:
resetToken
in classAction
- Parameters:
req
- The request object
-
getLocale
Gets the locale. -
saveMessages
Saves the messages to the request.- Overrides:
saveMessages
in classAction
- Parameters:
req
- The request objectmes
- The action messages
-
saveErrors
Deprecated.Use saveErrors(HttpServletRequest, ActionMessages) instead. This will be removed after Struts 1.2.Saves the errors to the request.- Parameters:
req
- The request objecterrs
- The action errors
-