Struts

Java-Examples

                                                                                                                                                                                                                    Show all | Close all
  • Overview

    • What is framework

      Framework is set of reusable software program that forms the basis for an application. Frameworks helps the programmers to build the application quickly. Earlier it was very hard to develop complex web applications. Now its very easy to develop such application using different kinds of frameworks such as Struts, Struts 2, Hibernate, JSF, Tapestry, JUnit, Log4j, Spring etc. In Java technology there are so many frameworks that helps the programmers to build complex applications easily. You can choose these frameworks for building your applications.

      Software framework

      Framework software in computer system is a layered structure that indicates what kind of program should be built and how they would interrelate to one another. In computer system, a framework is a conceptual structure that sometime includes actual programs, which specify programming interface or offer programming tools for using the frameworks.
    • Java Collection Framework

      We have tried you to make a walk through the Collection Framework. The Collection Framework provides a well-designed set if interface and classes for sorting and manipulating groups of data as a single unit, a collection.
      The Collection Framework provides a standard programming interface to many of the most common abstractions, without burdening the programmer with too many procedures and interfaces.
      The Collection Framework is made up of a set of interfaces for working with the groups of objects. The different interfaces describe the different types of groups. For the most part, once you understand the interfaces, you understand the framework. While you always need to create specific, implementations of the interfaces, access to the actual collection should be restricted to the use of the interface methods, thus allowing you to change the underlying data structure, without altering the rest of your code.

      In the Collections Framework, the interfaces Map and Collection are distinct with no lineage in the hierarchy. The typical application of map is to provide access to values stored by keys.
      When designing software with the Collection Framework, it is useful to remember the following hierarchical relationship of the four basic interfaces of the framework.
      • The Collection interface is a group of objects, with duplicates allowed.
      • Set extends Collection but forbids duplicates.
      • List extends Collection also, allows duplicates and introduces positional indexing.
      • Map extends neither Set nor Collection
    • Types of Framework

      Struts Struts Frame work is the implementation of Model-View-Controller (MVC) design pattern for the JSP. Struts is maintained as a part of Apache Jakarta project and is open

      Open Source Web Frameworks in Java

      1. Struts
        Struts Frame work is the implementation of Model-View-Controller (MVC) design pattern for the JSP. Struts is maintained as a part of Apache Jakarta project and is open source. Struts Framework is suited for the application of any size. Latest version of struts can be downloaded from http://jakarta.apache.org/.
         
      2. Turbine
        Turbine is a servlet based framework that allows experienced Java developers to quickly build web applications. Turbine allows you to use personalize the web sites and to use user logins to restrict access to parts of your application.
         
      3. Expresso Framework
        A powerful, open standards-based, enterprise-strength J2EE architectural framework providing a library of extensible application development components for quickly building web-based applications.
         
      4. Tapestry
        Tapestry is a powerful, open-source, all-Java framework for creating leading edge web applications in Java. Tapestry reconceptualizes web application development in terms of objects, methods and properties instead of URLs and query parameters. Tapestry is an alternative to scripting environments such as JavaServer Pages or Velocity. Tapestry goes far further, providing a complete framework for creating extremely dynamic applications with minimal amounts of coding.
         
      5. WebWork
        WebWork is a Java web-application development framework. It is built specifically with developer productivity and code simplicity in mind. WebWork is built on top of XWork, which provides a generic command pattern framework as well as an Inversion of Control container. In addition to these features, WebWork provides robust support for building reusable UI templates, such as form controls, UI themes, internationalization, dynamic form parameter mapping to JavaBeans, robust client and server side validation, and much more.
         
      6. Apache Cocoon
        Apache Cocoon is a web development framework built around the concepts of separation of concerns and component-based web development. Cocoon implements these concepts around the notion of 'component pipelines', each component on the pipeline specializing on a particular operation. This makes it possible to use a Lego(tm)-like approach in building web solutions, hooking together components into pipelines without any required programming. Cocoon is "web glue for your web application development needs". It is a glue that keeps concerns separate and allows parallel evolution of all aspects of a web application, improving development pace and reducing the chance of conflicts.
         
      7. Spring
        Spring is a layered Java/J2EE application framework, based on code published in Expert One-on-One J2EE Design and Development.
         
      8. Maverik
        Maverick is a Model-View-Controller (aka "Model 2") framework for web publishing using Java and J2EE. It is a minimalist framework which focuses solely on MVC logic, allowing you to generate presentation using a variety of templating and transformation technologies. In principle it combines the best features of Struts, WebWork, and Cocoon2.

          
      9. Anvil
        Anvil is a Java based server environment and object oriented programming language with templating support, being especially well-suited to for web applications.
          
      10. Jaffa
        JAFFA is aimed at Software development projects that want to focus their energy on building Business Functionality, without spending time on developing the underlying architecture. The JAFFA Project intends to provide a real world application framework, and then build a community of developers around that, who all want an open standards based framework that they can invest in, for building their specific applications on.
          
      11. Japple
        Japple is a rapid application development environment for building web applications and services. Built on the JavaTM2 Platform and open-standards, Japple allows you to develop and deploy web applications faster, easier and more efficiently than traditional methods.
         
      12. JPublish
        JPublish is a powerful web publishing system designed to ensure a clean separation of developer roles. JPublish includes support for multiple templating engines, including Jakarta Apache's Velocity, FreeMarker and WebMacro. JPublish supports numerous scripting languages including Python, BeanShell, and JavaScript. JPublish is modular and provides for easy extensibility.
         
      13. Jucas
        Jucas is a web-framework which brings together the pull MVC concept with component orientated design GUI programming.

        Struts (like other Model II frameworks) have brought the separation between View and Model and Controler to the web programming. On the other hand recent frameworks like Java Server Faces (JSF) or ASP.NET try to provide the advantages of object (component) orientated GUI-Design known from 'fat-client' apis like Swing or Visual Basic (stateful objects, event-mechanismus).

        Jucas combines both approaches. Stateful components (JavaBeans) are used to represent the model and the controller and templates use this components to render the view.
         
      14. MyFaces
        JavaServer(tm) Faces is a new and upcoming web application framework that accomplishes the MVC paradigm. It is comparable to the well-known Struts Framework but has features and concepts that are beyond those of Struts.
        Look at Sun's JavaServer(tm) Page to learn more about the Java Specification Request 127 and to download the specification. They also provide a useful Tutorial there.
         
      15. WebOnSwing
        WebOnSwing is a revolutionary multiple environment application framework that allows you to create web applications in the same way you develope a desktop one. You dont need to use JSP files, special tags, XML files, requests, posts, etc. Everything is Java and pure HTML files that comes directly from the graphic designer.
         
      16. Chrysalis
        Chrysalis is a Java web development framework. It has a different focus from most Model-View-Controller (MVC) web frameworks. Chrysalis controllers resemble normal Java classes with multiple methods. Client request URLs are mapped to each controller method. The typical MVC framework is founded on one basic insight: that Java servlets can be treated as an event handler for the submit button of HTML forms. This makes servlets analogous to the controller in the MVC pattern, equivalent to the Listener classes used in Java GUIs. From this insight, the rest of the pattern follows easily (see Struts for the most popular implementation of this approach).
          
      17. VRaptor
        VRaptor is a Model-View-Controller web application framework that tries to implement the best features from the following state of art MVC frameworks: WebWork 2, Spring Framework and Struts. It is highly focused on the Inversion of Control principles, using the Constructor Injection philosophy brought by the PicoContainer.
         
      18. Swinglets
        Program your JSP & Servlets like you program your Swing components. Swinglets is a server side component library that uses an identical design to Swing. Swinglets has look and feels for HTML, JavaScript and WML. The Components, Models, Renderers, and LookAndFeels are very similar. It has Swing event handling too. In fact Swinglets actually uses the Swing models (e.g. TableModel). This means you can take your existing models and start working with Servlets straight away. It's just about as close to a standard as you can get without it actually coming from Sun themselves.
         
      19. Millstone
        Millstone is a user interface library for development of networked Java applications. It provides a terminal independent component model that can be adapted to different terminal types and user interface themes. The development model of Millstone is closely related to traditional client side UI development: it has a continuous application lifecycle and an extensive event model. The Millstone library also provides an interface for directly connecting UI components to business logic and data storage.
         
      20. Wicket
        Wicket is a Java web application framework that takes simplicity, separation of concerns and ease of development to a whole new level. Wicket pages can be mocked up, previewed and later revised using standard WYSIWYG HTML design tools. Dynamic content processing and form handling is all handled in Java code using a Swing-like component model backed by POJO data beans that can easily be persisted with Hibernate.
          
  • Struts framework

    Apache Struts is an open-source web application framework for developing Java EE web applications. It uses and extends the Java Servlet API to encourage developers to adopt a model-view-controller (MVC) architecture. It was originally created by Craig McClanahan and donated to the Apache Foundation in May, 2000. Formerly located under the Apache Jakarta Project and known as Jakarta Struts, it became a top-level Apache project in 2005.
  • Overview

    In a standard Java EE web application, the client will typically call to the server via a web form. The information is then either handed over to a Java Servlet which interacts with a database and produces an HTML-formatted response, or it is given to a JavaServer Pages (JSP) document that intermingles HTML and Java code to achieve the same result. Both approaches are often considered inadequate for large projects because they mix application logic with presentation and make maintenance difficult. The goal of Struts is to separate the model (application logic that interacts with a database) from the view (HTML pages presented to the client) and the controller (instance that passes information between view and model). Struts provides the controller (a servlet known as ActionServlet) and facilitates the writing of templates for the view or presentation layer (typically in JSP, but XML/XSLT and Velocity are also supported). The web application programmer is responsible for writing the model code, and for creating a central configuration file struts-config.xml that binds together model, view and controller. Requests from the client are sent to the controller in the form of "Actions" defined in the configuration file; if the controller receives such a request it calls the corresponding Action class that interacts with the application-specific model code. The model code returns an "ActionForward", a string telling the controller what output page to send to the client. Information is passed between model and view in the form of special JavaBeans. A powerful custom tag library allows it to read and write the content of these beans from the presentation layer without the need for any embedded Java code. Struts is categorized as a request-based web application framework.[1] Struts also supports internationalization by web forms, and includes a template mechanism called "Tiles" that (for instance) allows the presentation layer to be composed from independent header, footer, and content components.
  • Competing MVC frameworks

    Although Struts is a well-documented, mature, and popular framework for building front ends to Java applications, there are other frameworks categorized as "lightweight" MVC frameworks such as Spring MVC, Stripes, Wicket, Play!, and Tapestry. The new XForms standards and frameworks may also be another option to building complex web form validations with Struts in the future. The WebWork framework spun off from Apache Struts aiming to offer enhancements and refinements while retaining the same general architecture of the original Struts framework. However, it was announced in December 2005 that Struts would re-merge with WebWork. WebWork 2.2 has been adopted as Apache Struts2, which reached its first full release in February 2007. In 2004, Sun launched an addition to the Java platform, called JavaServer Faces (JSF). Aside from the original Struts framework, the Apache project previously offered a JSF-based framework called Shale, which was retired in May 2009.[2] Other MVC frameworks that are Java-based include Grails. C
  • Sample "Hello World" Program

    Struts HelloWorld Program using Eclipse IDE with Pictorial Presentation

    Developing First struts project using Eclipse IDE

    1. First open Eclipse ide struts helloworld program eclipse ide

    After opening the Eclipse IDE you have to create a Workspace.

    Click 'File --> New-->Dynamic Web Project

    struts helloworld program eclipse ide

    After Clicking Dynamic Project it prompts for project name.

    Enter Project name and click finish

    struts helloworld program eclipse ide

    web.xml files is in WEB-INF directory

    struts helloworld program eclipse ide

    Now you have successfully created a struts Project

    In the Next step you have to add jar files to lib directory

    Open WEB-INF in webcontent folder. There you can see lib directory

    Add suitable jar files to lib directory by copying and paste the jar files in lib directory

  • Struts MVC Architecture and Design Pattern

    Struts MVC Design Pattern (Model View Controller)

    • Struts is an open source MVC framework used to seperate Model, View and Controller.
    • It uses Servlets 2.2 and JSP 1.1 Tags.
    • When comparing to one page approach ie. coding in single JSP Page
    • It is very difficult for the programmers to debug and it looks very ugly.
    • As the JSP coding becomes larger and implementing Javascript on it, then its mind blowing job for programmer.
    • Difficult to differentiate JSP, JAVA and Javascript coding.
    • To understand full flow we have to go through all pages .
    • The syntax colors of different coding creates big blow to programmer.
    • One page coding is discouraged by all programmers.
    • Model
    1. Model Contains Core Application functionalities.
    2. It is used to manipulate and access data.
    3. Model is related to Data Sources to access DB.
    4. It has Business Logic.
    • View
    1. View is the user interface to display data or to get input from user.
    2. Here JSP is the View part.
    3. View provides presentation of the Model it means view should be notified after changes to model occurs.
    • Controller
    1. Controller is the ActionServlet which flow controls mechanism by which user interacts with application.
    2. Struts provides an Action class from org.apache.struts.action.Action.

    Struts Flow Architecture

    • Struts Flow
    1. If an action is called it maps to web.xml.
    2. Web.xml forward the action call to struts-config.xml.
    3. Then struts-config.xml maps the action and form beans.
    4. Setter and Getter method created in ActionForm is activated.
    5. Then ActionServlet is requested
  • Download

    Click here to download struts 2.3.4.1