The framework documentation is written for active web developers and assumes a working knowledge about how Java web applications are built. For more about the underlying nuts and bolts, see the Key Technologies Primer.
Follow along with these tutorials to get started using Struts 2. The example code for the tutorials available for checkout from the Struts 2 GitHub repository at struts-examples.The example projects use Maven to manage the artifact dependencies and to build the .war files.
I have needed to maintain a Struts 1 application. I know, EOL almost two years ago, no new releases in six years. Whatever, we have 100k lines of working code in a Struts 1 app, and it's not going away just because I have more modern sensibilities.
I've looked for the docs, so I can understand this ancient framework, and I'm coming up empty. This link is broken. This site seems to only have Struts 2 information, if you don't count the EOL announcement.
All resources will stay where they are. The documentation will still be accessible from the Apache Struts homepage, as well as the downloads for all released Struts 1.x versions. All of the Struts 1 source code can be found in the Apache Struts subversion repository, now and in future. All released Maven artifacts will still be accessible in Maven Central.
Please be aware that the framework is using Log4j2 now as a main logging layer, the existing old logging layer is deprecated and will be removed soon. Log4j2 supports many different logging implementations, please check documentations for more details.
As from Struts 2.5.12 a new conversion logic was introduced which can affect your applications when using uncommon solutions. One of these is to use a number literals in Freemarker template. In such case Freemarker treats them as numbers (as BigDecimals) and Struts logic converts them to a string with decimal zero, see the example below:
An Action is an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request. The controller (ActionServlet) will select an appropriate Action for each request, create an instance (if necessary), and call the perform method.
Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. This means you should design with the following items in mind:
When an Action instance is first created, the controller servlet will call setServlet() with a non-null argument to identify the controller servlet instance to which this Action is attached. When the controller servlet is to be shut down (or restarted), the setServlet() method will be called with a null argument, which can be used to clean up any allocated resources in use by this Action.
For each request processed by the controller servlet, the ModuleConfig object for the module selected by the request URI currently being processed will also be exposed under this key as a request attribute.
Since: Struts 1.1See Also:Constant Field ValuesDATA_SOURCE_KEYpublic static final java.lang.String DATA_SOURCE_KEYDeprecated. Replaced by Globals.DATA_SOURCE_KEYThe context attributes key under which our default configured data source (which must implement javax.sql.DataSource) is stored, if one is configured for this module.See Also:Constant Field ValuesERROR_KEYpublic static final java.lang.String ERROR_KEYDeprecated. Replaced by Globals.ERROR_KEYThe request attributes key under which your action should store an org.apache.struts.action.ActionErrors object, if you are using the corresponding custom tag library elements.See Also:Constant Field ValuesEXCEPTION_KEYpublic static final java.lang.String EXCEPTION_KEYDeprecated. Replaced by Globals.EXCEPTION_KEYThe request attributes key under which Struts custom tags might store a Throwable that caused them to report a JspException at runtime. This value can be used on an error page to provide more detailed information about what really went wrong.See Also:Constant Field ValuesFORM_BEANS_KEYpublic static final java.lang.String FORM_BEANS_KEYDeprecated. Replaced by collection in ModuleConfigThe context attributes key under which our org.apache.struts.action.ActionFormBeans collection is normally stored, unless overridden when initializing our ActionServlet.See Also:Constant Field ValuesFORWARDS_KEYpublic static final java.lang.String FORWARDS_KEYDeprecated. Replaced by collection in ModuleConfig.The context attributes key under which our org.apache.struts.action.ActionForwards collection is normally stored, unless overridden when initializing our ActionServlet.See Also:Constant Field ValuesLOCALE_KEYpublic static final java.lang.String LOCALE_KEYDeprecated. Replaced by Globals.LOCALE_KEYThe session attributes key under which the user's selected java.util.Locale is stored, if any. If no such attribute is found, the system default locale will be used when retrieving internationalized messages. If used, this attribute is typically set during user login processing.See Also:Constant Field ValuesMAPPING_KEYpublic static final java.lang.String MAPPING_KEYDeprecated. Replaced by Globals.MAPPING_KEYThe request attributes key under which our org.apache.struts.ActionMapping instance is passed.See Also:Constant Field ValuesMAPPINGS_KEYpublic static final java.lang.String MAPPINGS_KEYDeprecated. Replaced by collection in ModuleConfigThe context attributes key under which our org.apache.struts.action.ActionMappings collection is normally stored, unless overridden when initializing our ActionServlet.See Also:Constant Field ValuesMESSAGE_KEYpublic static final java.lang.String MESSAGE_KEYDeprecated. Replaced by Globals.MESSAGE_KEYThe request attributes key under which your action should store an org.apache.struts.action.ActionMessages object, if you are using the corresponding custom tag library elements.Since: Struts 1.1See Also:Constant Field ValuesMESSAGES_KEYpublic static final java.lang.String MESSAGES_KEYDeprecated. Use Globals.MESSAGES_KEY instead.The base of the context attributes key under which our module MessageResources will be stored. This will be suffixed with the actual module prefix (including the leading "/" character) to form the actual resources key.
For each request processed by the controller servlet, the MessageResources object for the module selected by the request URI currently being processed will also be exposed under this key as a request attribute.
Since: Struts 1.1See Also:Constant Field ValuesSERVLET_KEYpublic static final java.lang.String SERVLET_KEYDeprecated. Use Globals.SERVLET_KEY instead.The context attributes key under which we store the mapping defined for our controller serlet, which will be either a path-mapped pattern (/action/*) or an extension mapped pattern (*.do).See Also:Constant Field ValuesTRANSACTION_TOKEN_KEYpublic static final java.lang.String TRANSACTION_TOKEN_KEYDeprecated. Use Globals.TRANSACTION_TOKEN_KEY instead.The session attributes key under which our transaction token is stored, if it is used.See Also:Constant Field Valuestokenprivate static TokenProcessor tokenAn instance of TokenProcessor to use for token functionality.defaultLocaleprotected static java.util.Locale defaultLocaleThe system default Locale.servletprotected ActionServlet servletThe controller servlet to which we are attached.Constructor DetailActionpublic Action()Method DetailgetServletpublic ActionServlet getServlet()Return the controller servlet instance to which we are attached.setServletpublic void setServlet(ActionServlet servlet)Set the controller servlet instance to which we are attached (if servlet is non-null), or release any allocated resources (if servlet is null).Parameters:servlet - The new controller servlet, if anyexecutepublic ActionForward execute(ActionMapping mapping, ActionForm form, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws java.lang.ExceptionProcess the specified non-HTTP request, and create the corresponding non-HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic. Return an ActionForward instance describing where and how control should be forwarded, or null if the response has already been completed. The default implementation attempts to forward to the HTTP version of this method.Parameters:mapping - The ActionMapping used to select this instanceform - The optional ActionForm bean for this request (if any)request - The non-HTTP request we are processingresponse - The non-HTTP response we are creatingThrows:java.lang.Exception - if the application business logic throws an exceptionSince: Struts 1.1executepublic ActionForward execute(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.ExceptionProcess the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic. Return an ActionForward instance describing where and how control should be forwarded, or null if the response has already been completed.Parameters:mapping - The ActionMapping used to select this instanceform - The optional ActionForm bean for this request (if any)request - The HTTP request we are processingresponse - The HTTP response we are creatingThrows:java.lang.Exception - if the application business logic throws an exceptionSince: Struts 1.1performpublic ActionForward perform(ActionMapping mapping, ActionForm form, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws java.io.IOException, javax.servlet.ServletExceptionDeprecated. Use the execute() method insteadProcess the specified non-HTTP request, and create the corresponding non-HTTP response (or forward to another web component that will create it). Return an ActionForward instance describing where and how control should be forwarded, or null if the response has already been completed. The default implementation attempts to forward to the HTTP version of this method.Parameters:mapping - The ActionMapping used to select this instanceform - The optional ActionForm bean for this request (if any)request - The non-HTTP request we are processingresponse - The non-HTTP response we are creatingThrows:java.io.IOException - if an input/output error occursjavax.servlet.ServletException - if a servlet exception occursperformpublic ActionForward perform(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletExceptionDeprecated. Use the execute() method insteadProcess the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it). Return an ActionForward instance describing where and how control should be forwarded, or null if the response has already been completed.Parameters:mapping - The ActionMapping used to select this instanceform - The optional ActionForm bean for this request (if any)request - The HTTP request we are processingresponse - The HTTP response we are creatingThrows:java.io.IOException - if an input/output error occursjavax.servlet.ServletException - if a servlet exception occursgenerateTokenprotected java.lang.String generateToken(javax.servlet.http.HttpServletRequest request)Generate a new transaction token, to be used for enforcing a single request for a particular transaction.Parameters:request - The request we are processinggetDataSourceprotected javax.sql.DataSource getDataSource(javax.servlet.http.HttpServletRequest request)Return the default data source for the current module.Parameters:request - The servlet request we are processingSince: Struts 1.1getDataSourceprotected javax.sql.DataSource getDataSource(javax.servlet.http.HttpServletRequest request, java.lang.String key)Return the specified data source for the current module.Parameters:request - The servlet request we are processingkey - The key specified in the element for the requested bundleSince: Struts 1.1getLocaleprotected java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request)Return the user's currently selected Locale.Parameters:request - The request we are processinggetResourcesprotected MessageResources getResources()Deprecated. This method can only return the resources for the default module. Use getResources(HttpServletRequest) to get the resources for the current module.Return the message resources for the default module.getResourcesprotected MessageResources getResources(javax.servlet.http.HttpServletRequest request)Return the default message resources for the current module.Parameters:request - The servlet request we are processingSince: Struts 1.1getResourcesprotected MessageResources getResources(javax.servlet.http.HttpServletRequest request, java.lang.String key)Return the specified message resources for the current module.Parameters:request - The servlet request we are processingkey - The key specified in the element for the requested bundleSince: Struts 1.1isCancelledprotected boolean isCancelled(javax.servlet.http.HttpServletRequest request)Returns true if the current form's cancel button was pressed. This method will check if the Globals.CANCEL_KEY request attribute has been set, which normally occurs if the cancel button generated by CancelTag was pressed by the user in the current request. If true, validation performed by an ActionForm's validate() method will have been skipped by the controller servlet.
c80f0f1006