Skip to main content

What is Struts framework in Java?


Struts framework helps for developing the web based applications. Struts java framework is one of the most popular framework for web based applications.Java servlet, JavaBeans, ResourceBundles and XML etc are the Jakarta commons packages used for accomplishing this purpose. This is an open source implementation of MVC pattern for the development of web based application. The features of this type of framework are,

More robust or reliable architecture
Helps for development of application of any size
Easy to design
Scalable
Reliable web application with java.

Struts Framework

When a request happens the parameters interceptor passes the requested data to the ValueStack. After transferring the request the OGNL do the job of changing the string based form data to their related java types. OGNL complete or do this by using the set of available built-in type converters. After that when the results are generated the OGNL converts the java types of the property on the ValueStack to the string-based HTML output. ActionContext is act as thread local which helps the values stored in the ActionContext are unique per thread, this makes the Struts 2 actions thread safe.

Strut implements the Model-View-Controller (MVC) design pattern.


Structure of Struts Application

Model: – The model includes the core of the application’s functionality. It wraps the state of the application. Sometimes the only functionality it contains is state. Model category not bothered about the view or controller category.
View: – The view gives the presentation of the model. It is the look of the application. The view can access the model getters, but it has no knowledge of the setters. In addition, it knows nothing about the controller. The view should be notified when changes to the model occur.
Controller: – The controller reacts to the user input. It creates and sets the model.
The MVC implemented by the action, result and FilterDispatcher respectively. In MVC the controller’s job is to map the user request to appropriate action and this job is done by FilterDispatcher. The model includes the data and the business logic and the model is implemented by the action component. The presentation component of the MVC pattern is view and view is implemented using JSP, Velocity Template, Freemaker or some other presentation-layer technology.

Struts components

1) Action handler:- The action handler interacts with other layers

2) Result Handler: – The result handler actually dispatches the request to view.

3) Custom Tags:- The custom Tags are used render the dynamic content

4) Interceptors: – An interceptor permits to adding some custom logic such as authentication, file upload to an action. Interceptors code is run before and after an Action is invoked

5) Value Stack: – The ValueStack permits the expression language to find property values across multiple objects. Thus Struts2 tags can access data from the action very easily.

6) Expression Language:- Struts 2 expression language is used for getting and setting properties of Java objects

7) Controller: – The controller receives all incoming requests. Its primary function is the mapping of a request URI to an action class selecting the proper application module.

8) Struts-config.xml file:- This file includes all of the routing and configuration information for the Struts application.

9) Action classes: – It’s the developer’s responsibility to create these classes. They act as bridges between user-invoked URIs and business services. Actions process a request and return an ActionForward object that identifies the next component to invoke. They’re part of the Controller layer, not the Model layer.

10) View resources:- The view resources includes Java Server Pages, HTML pages, JavaScript and Stylesheet files, Resource bundles, JavaBeans, and Struts JSP tags.

11) ActionForms: – These greatly simplify user form validation by capturing user data from the HTTP request. They act as a “firewall” between forms (Web pages) and the application (actions). These components allow the validation of user input before proceeding to an Action. If the input is invalid, a page with an error can be displayed.

12) Model componenets: – The Struts Framework has no built-in support for the Model layer. A strut supports any model components. Some model components are,

1) JavaBeans

2) EJB

3) CORBA

4) JDO

5) any other

Features of strut frameworks

1) Open source

2) Implements the JSP Model 2 Architecture

3) Stores application routing information and request mapping in a single core file, struts-config.xml

4) The Struts Framework, itself, only fills in the View and Controller layers. The Model layer is left to the developer

5) OGNL and ValueStack: – OGNL stands for Object-Graph Navigation Language and it is a powerful expression language that is used to reference and manipulate data on the ValueStack. OGNL provides a mechanism of data transfer and type conversion. OGNL expression language provides simplified syntax to reference java objects. OGNL is used to bind the java-side data properties to the string-based view layer. In Struts 2 the action resides on the ValueStack which is a part of the ActionContext. ActionContext is a global storage area that holds all the data associated with the processing of a request.

Comments

Popular posts from this blog

The Future of Java Developers in the AI Decade

In this AI decade, Java developers are positioned to play a crucial role in various areas: 1. AI and Machine Learning: While Python is often the language of choice for AI and machine learning, Java still has its place, especially in enterprise-level applications and systems where stability, scalability, and security are paramount. Java developers can work on integrating AI and machine learning capabilities into existing Java-based systems or developing new AI-powered applications using Java frameworks like Deeplearning4j or Weka. 2. Big Data and Analytics: With the growing importance of big data analytics, Java developers can contribute to building robust data processing and analytics systems. Java is widely used in big data frameworks like Apache Hadoop and Apache Spark, enabling developers to work on distributed computing, data processing, and real-time analytics applications. 3. Cloud Computing: As more companies move their infrastructure to the cloud, Java developers can leverage t

What is JDK, JRE and JVM?

What are JDK, JRE, and JVM: JDK :- Java Development Kit (in short JDK) is Kit which provides the environment to Develop and execute(run ) the Java program. For eg. You(as Java Developer) are developing an accounting application on your machine, so what do you going to need into your machine to develop and run this desktop app? You are going to need  J-D-K  for that purpose for this you just need to go to the official website of sun or oracle to download the latest version of JDK into your machine. Hence, JDK is a kit(or package) which includes two things i) Development Tools(to provide an environment to develop your java programs) and ii) JRE (to execute your java program). JDK is only used by Java Developers. JRE: - Java Runtime Environment (to say JRE) is an installation package which provides an environment to only run(not develop) the java program(or application)onto your machine. For eg(continuing with the same example) after developing your accounting application

Fresher Need to start from this technology

For freshers, some technologies are relatively simpler to start with due to their ease of learning and abundant resources available for beginners: 1. Python: Known for its readability and simplicity, Python is often recommended as a first language due to its clean syntax and vast community support. It's used in various fields like web development, data analysis, artificial intelligence, and more. 2. HTML/CSS: Fundamental for web development, HTML (HyperText Markup Language) and CSS (Cascading Style Sheets) are essential and relatively easy to grasp. They form the backbone of web pages and are essential for anyone interested in web development. 3. JavaScript:Alongside HTML and CSS, JavaScript is crucial for web development, adding interactivity and functionality to websites. It's beginner-friendly and essential for front-end development. 4. Java: Although it might have a steeper learning curve than Python, Java is widely used in enterprise applications, Android development, and