0

I'm currently learning Struts 1.3!

Why do we extend Action class in struts 1.3

public class LoginAction extends Action

And when i look into web.xml file the mapping says

<servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

what is the Significance of ActionServlet class, why ActionServlet is mapped with Action.

Thanks

Jay Jain
  • 73
  • 1
  • 8

1 Answers1

0

Simple answers:

  1. Because that's how Struts 1 works.
  2. Because you have to map requests to actions somehow.

Longer answers:

1. In S1 everything depends on subclassing framework classes.(See notes) The base Action class really only provides a small portion of framework functionality (messaging and resources, primarily), along with a small collection of other non-POJO framework classes, notably ActionForm.

In Struts (and in lots of older software) programs were written to implementations, not interfaces. Action is a class, not an interface. Most of the S1 framework's implementation references Action, meaning that in order to fulfill framework method signatures and return values, you must subclass Action.

2. One goal of MVC is to route requests to appropriate handlers. In S1 this is handled by the ActionServlet. It looks at the request and, based on the Struts configuration, determines which action will handle the request. It acts (more or less) as the controller.


For further study: A significant portion of functionality, and a main point of extension, lies further beneath the surface, in the RequestProcessor class. Note that instantiating actions to handle requests requires an Action to be returned. This means that requests must be handled by an Action, although any Action subclass may be used, e.g., your own actions, a framework action like DispatchAction or ForwardAction, etc.

I would add that your questions can be answered by reading the wealth of information available about Struts 1 on its site and on the internet. Since the source is available it's also important to check and verify assumptions against it. I might recommend looking at Struts 1.2 source instead of 1.3 since there's a small layer of functionality added that clouds the basics.

All this said, unless you have a very compelling reason to do so, studying Struts 1 is a waste of time. It's been EOL'd, hasn't been recommended for new projects for years, is written in a pretty old style, etc. Modern Java web frameworks are much, much easier to work with. Struts 1 was written a Pretty Long Time Ago, before inheritance had fallen out of favor, before annotations existed, before marker interfaces were used all over the place, etc.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • Thank you so much for you efforts! But for me learning on the Java related things (technology/framework) would help me to explore the implementations of Java technology. – Jay Jain May 29 '14 at 12:04
  • @JayJain And I'm saying study something that uses current best practices instead of something that forces you to write rigid, inflexible code. – Dave Newton May 29 '14 at 12:29
  • Actually I have to work on existing applications which are all in Struts 1.3. – Jay Jain Jun 02 '14 at 09:54