What is Struts

Struts are used to create Java web applications. Struts uses Model-View-Controller (MVC), tag libraries and their associated Java classes to create web applications.

What is Struts


Apache Struts is used to create Java web applications using Java Servlet API and Model-View-Controller (MVC) Architecture. Struts has a set of tag libaries and their associated Java classes.

Struts is open-source and uses Java Servlets, Java Server Pages and Java Beans. It interacts with databases and business logic engines to customize a response.

In a normal web application, client is called to a server, the information submitted is handed to Java Servlet that interacts with database to produce HTML response. The information can also be submitted to Java Server Pages that combines Java code with HTML.

Both approaches do not work when it comes to large projects and hence we require Struts.

Java Servlets:

Java Servlets reads and process data written in HTML form and generates result with this data. It then calls the business logic directly in the servlet.

Java Servlets is used to create dynamic websites with Java.

Before the servlet return the data to the browser, parameters are adjusted to the requirement of Browser.

Java Server Pages (JSP):

Java Server Pages (JSP) are text documents having java code that combines static HTML with dynamic generated contents of servlets. HTML code is embedded in the java code.

Java Beans:

Java Beans attributes (variables) are private. The access to these attributes is managed by getter and setter methods.

Struts framework has a Request handler, a Response handler and a tag library.

There are two versions of Struts: Struts 1.x framework that are used widely and Struts 2.x framework that provide elegant solutions to difficult problems.

Model-View-Controller:

View is the screen that is seen by user and is used to give or read information. Information are filled in HTML pages generated by JSP files and in the same way when showing results an HTML page will be generated by same JSP files.

The information by the user is first submitted in the HTML page and is then sent to the Controller i.e. Java Beans.

Controller takes the information submitted to the Model. The functions set in Model are only called by Controller and there is no link between Model and View hence this framework works faster and better. Controller then takes the result back to display it to the user through HTML pages.

Attributes used in Struts:

Id : tag uses this as the temporary name of the bean

Name : the name of a pre-existing bean

Property : of the bean of the name attribute

Scope : to search for the bean of the name attribute

Read more Struts tutorials at the index page of Struts Tutorials