What is a Framework?
Can I say JDK API and J2EE API are the Frameworks?
See, how java and j2EE is made up of -
Servlet API
EJB API
Persistence API
Net API
File System API
JDBC API
What are all above?
All these are basically set of interfaces and classes. Some classes are abstract, some are fully implemented.
Writing Servlet
When we write an Http Servlet by extending HttpServlet, we override doGet and doPost methods. What is the need? This is a guideline from framework. Framework says you need to implement these methods for handing the request and response as per your need.
Struts 1.1
There is a Struts API (set of interface and classes) from apache. It is composed of ActionServlet, Action, ActionForm, and ActionMappings etc.
We say struts as a Web Presentation Framework. Before this how do we write Web Presentation Part of the Applications?
We create multiple servlets which handle multiple requests and post request handling we route to the next servlet or the presentation JSP.
So what does struts as a Framework replaced–
Do not create N – servlets for handling N requests, instead configure one common servlet(ActionServlet as part of Struts Framework) which will be a single point of receiver for any request. To implement this each request action have a common (*.do) and this is mapped to a ActionServlet Mapping.
Now ActionServlet will receive the request, get the URI (say LoginAction.do) and ping the struts config file to see who is the Handler(Action Class) for this.
When we write the Action Class – Struts framework mandate us to –
Extend from Action(Struts Framework Class) - Guideline from a Framework
Wtite execute method (Guideline from Framework)
All actions needs to be configured in the struts-config.xml file - Guideline from struts.