Introduction to Struts:
- Struts Framework is the product of the Apache software foundation which is basically used for developing web applications in Java.
- Of three editions of Java - JSE, JEE and JME, struts framework resides in the middle tier (i.e. Java Enterprise Edition – JEE).
- As this framework is provided by Apache, it is also known as Apache Struts or Jakarta Struts. It was originally known as WebWork framework.
- Definition: Struts is an invasive, extensible as well as portable framework that is mainly used for software development, web-application development, application maintenance, application deployment etc.
Note: Invasive frameworks – The framework that provides a set of interfaces and classes, which the application has to implement or extend for its development, are termed as invasive frameworks. This provides a way to provide own implementation which makes the application extensible.
How Struts Framework Works?
- The basic directory structure of defining applications of Struts Framework is:
- Source Packages : The packages are of two types:
- Default packages – single level package. All the required action (.java) classes are placed here.
- Other (user-defined packages) – we can create multilevel packages here. Action classes can be placed here just as default package.The action classes contain the getter and setter methods of all the variables declared in the class. Plus, it also contains one method
- Libraries: All the necessary libraries such as “struts-tags”, JSTL’s EL, jdk, jre are placed here. The path of these libraries is also mentioned in context.xml. In the IDE’s like NetBeans or Eclipse, they get automatically created.
- Configuration Files: All the configuration files like : context.xml, web.xml, manifest.mf are to be placed under this folder. Here, context.xml and web.xml are same as defined above. The manifest files (manifest.mf) can have extensions of “.mf” or “manifest”. This file contains code that provides versatility to the code so that it can be executed on any platform. Any web application after deployment is transferred as either “war”, “rar” or “ear” extension. The manifest.mf file contains a “meta” tag which specifies the main file to execute when your web application is deployed.
- Web.xml: The core of any web application (using any framework) is web.xml. It is also known as Deployment descriptor. The file is to be placed under the Web - INF folder. It contains the actual running description of the application. Which file to run first, what should be the time-out of the sessions, which filters are to be implemented, what is the path of filters and other similar information is placed in web.xml
- Context.xml: The configuration file, context.xml is to be placed under META-INF folder. Context.xml contains the information about the path of the Apache Tomcat server, path of application resources such as images, audio-video files etc.