For creating Java web application,Apache Struts is used which is a free open-source framework
A D V E R T I S E M E N T
The framework provide three key components which are as follows:
A "request" handler is provided by the application developer
that is mapped to the standard URI .
A "response" handler which is responsible to transfer control to another
resource which completes the response.
A tag library is used to help developer create interactive
form-based applications with server pages.
What is Struts?
Model-View-Controller (MVC) design pattern is used by Struts Framework which is the implementation of the JSP.
Struts is open source and is also maintained as a part of Apache Jakarta project.
Struts Framework is well suited for application of any size.
Major Versions of Struts
Two major versions of
Struts framework is offered by the Apache Struts Project. For the Java,Struts 1 is recognized as the
most popular web application framework. The struts 1.x
framework is the mature, well-documented, and widely supported.
Struts 1 is the best choice for the teams who value proven
solutions to common problems.
Other name of Struts 2 was WebWork 2. The WebWork and the Struts
communities joined forces to create Struts 2 after working
independently for several years. For teams who value elegant
solutions to difficult problems,the new
framework is best choice .
In the fourth
quarter of the 2006,a stable release of Struts 2 is expected . A BETA release is also available now.
The Six Basic Steps in Using Jakara Struts
Modify struts-config.xml.
In addition to forward and action
elements used to specify the
destination URLs and Action object, we use
the form-bean element to declare form
beans. We also add the scope and name
attributes to the action element to tie
the form bean to the Action.
Optionally, to declare a properties file containing
the standard messages, names, and labels,we add a message-resources
element .
Define a form bean.
This bean has the properties (i.e., getter and setter methods)
corresponding to each of the incoming request
parameters and normally extends ActionForm
and . Alternatively,in which case it will contain
a Map representing the request
parameters, the bean can extend
the DynaActionForm.
Create results beans.
These are normal beans of which is used in MVC when
implemented directly with RequestDispatcher.
That is, they represent the data access code and results of the business
logic. These beans are stored
in request, session, or application scope with the use of
setAttribute method of
HttpServletRequest, HttpSession,
or ServletContext, just as in the normal
non-Struts applications.
Create an Action object to
handle requests.
Rather than calling request.getParameter
explicitly as in the previous example, we can use the
execute method casts the ActionForm
argument to the specific form bean class, then uses
getter methods to access the properties of the
object.
Create form that invokes blah.do.
This form can use the bean:message tag
to output text labels and standard messages that are
defined in the properties file that is declared with the
message-resources in struts-config.xml
Display results in JSP.
The JSP page uses the bean:write tag to
output properties of the result bean and form bean . It
may also use the bean:message tag to
output text labels and standard messages that are
defined in standard properties file.
Advantages of Using Struts
Centralized File-Based Configuration.
Rather than hard-coding information into Java
programs, many Struts values are represented in the property
or XML files. This loose coupling means that
many changes can be made without recompiling or modifying
the Java code, and that wholesale changes
can be made by editing a single file. This approach
also lets Web developers and Java focus on their
specific tasks (implementing business logic,
presenting certain values to clients, etc.) without
needing to know about overall system layout.
Form Beans.
In JSP,To automatically
populate a JavaBean component based on the incoming
request parameters, you can use property="*" with
jsp:setProperty . Unfortunately, however, in the
standard API this capability is unavailable to the
servlets, even though with MVC it is really servlets,
not JSP pages, that should usually be the target of
form submissions. Apache Struts extends this
capability to Java code and adds in several useful
utilities, all of which serve to greatly simplify
the processing of the request parameters.
Bean Tags.
Apache Struts provides a set of custom JSP tags (bean:write,
in particular) that let you easily output the
properties of JavaBeans component. Basically, these
are concise and powerful variations of standard
jsp:useBean and jsp:getProperty
tags.
HTML Tags.
Apache Struts provides a set of custom JSP tags to
create HTML forms that are associated with the JavaBeans
components. This bean/form association serves two
useful purpose:
It lets you get initial form-field values
from the Java objects.
It lets you to redisplay forms with some or all
previously entered values intact.
Form Field Validation.
Apache Struts has builtin capabilities for checking
that form values are in required format. If
values are missing or in an improper format, the
form can be automatically redisplayed with the error
messages and with the previously entered values
maintained.
This validation can be performed on server
(in Java), or both on server and on client
(in JavaScript).
Consistent Approach.
Struts encourages consistent use of MVC throughout of
your application
Disadvantages of Using Struts
Bigger Learning Curve.
To use MVC with the standard RequestDispatcher,
you need to be comfortable with the standard JSP and
servlet API and a large and elaborate framework that is
almost equal in size to the core system. This
drawback is especially significant with smaller
project, near-term deadlines, and less experienced
developers; you could spend as much time learning
Struts as building your actual system.
Worse Documentation.
Compared to the standard servlets and JSP APIs,
Struts has fewer online resources, and many
first-time users find the online Apache
documentation confusing and poorly organized. There
are also fewer books on the Apache Struts than on
standard servlets and JSP.
Less Transparent.
With Struts applications, there is a lot more going
on behind scenes than with normal Java-based Web
applications. As a result, Struts applications always are:
Harder to benchmark and optimize
Harder to understand
Rigid Approach.
The flip side of the benefit that Struts encourages
a consistent approach to MVC is that Struts makes it
difficult to use other
approaches.
What You Should Already Know
Before you goes to this tutorial you should have a basic understanding of
the following:
HTML
A basic understanding of JAVA
JSP
Servlets
JDBC
Custom Tags
If you are going to study these subjects first, find the tutorial
on our Home page