Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Wednesday, August 19, 2009

Working Of Struts 2 Hello World


In my previous post on Getting started with struts 2, i have explained about the configuration of eclipse, the localhost server and the folder structure of a hello world program. Now let me explain the flow of the project and its working of the struts-blank project.

Struts is purely based on the Model- View- Contoller (MVC) design pattern. It is one of the best and most well developed design patterns in use. By using the MVC architecture we break the processing in three sections named Model, the View, and the Controller.

The struts container first of all reads the WEB-INF/web.xml file which instructs the server to use the required filter and mapping conditions. This is the file which has got the welcome list tag. You must specify the file name in the welcome-list tag, whichever you want as the index file for your project.

In struts application we have another xml file which is a Struts configuration file named as struts.config.xml. The name of this file can be changed. The name of the struts configuration file can be configured in the web.xml file. This file is placed under the WEB-INF directory of the web application. It is an XML document that describes all or part of Struts application. In our project it is nothing but the struts.xml file which include the example.xml file. These two xml files acts as the controller. When ever a action is called, the control flow to struts.xml and finds the corresponding class file linked to that action. The class files are the compiled form of java file which are the actual performer in the project. These file contains the getter setter methods and the database handling codes. Generally these java files are called as the Model. Every function in the class has got the SUCCESS and FAILURE, depending upon the result the corresponding jsp files are linked in the controller. Those jsp files are called as View. In the run time controller acts as the interface between the model and view.

In this Hello world, first of all the web.xml file is called, that tells
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter as filter and the index.html as welcome file. In index.html a action is being called, the corresponding class file(java page - model) and the result page(jsp page - view) will be found in the struts.xml file. Now the HelloWorld.java file in the WEB-INF/example folder will be executed because helloworld.action is called from index.html. In HelloWorld.java the string 'MESSAGE' is assigned to a value by retriving it from the package.properties file through getter and setter methods. Then the output of the program is show in the HelloWorld.jsp file as mentioned in the struts.xml.

The same control flow applies for all the Complex project, first try to run this project and understand its flow which will make you feel comfortable when handling complex projects. Lot more example are available in the same pack downloaded from Apache struts. Try all those examples. Get more details and simple explanations on struts from

Thursday, June 25, 2009

Struts 2


Apache Struts 2 is an elegant, extensible framework for creating enterprise-ready Java web applications. The framework is designed to streamline the full development cycle, from building, to deploying, to maintaining applications over time.

Apache Struts 2 was originally known as WebWork 2. After working independently for several years, the WebWork and Struts communities joined forces to create Struts. This new version of Struts is simpler to use and closer to how Struts was always meant to be.

You can get more information about struts and struts itself from http://struts.apache.org/

Apache Struts is an open-source framework that is used for developing Java web application. Originally developed by the programmer and author Craig R. McClanahan, this was later taken over by the Apache Software Foundation in 2002. Struts have provided an excellent framework for developing application easily by organizing JSP and Servlet based on HTML formats and Java code. Strut1 with all standard Java technologies and packages of Jakarta assists to create an extensible development environment. However, with the growing demand of web application, Strut 1 does not stand firm and needs to be changed with demand. This leads to the creation of Strut2, which is more developer friendly with features like Ajax, rapid development and extensibility.

Struts is a well-organized framework based on MVC architecture. In Model-View-Controller Architecture, Model stands for the business or database code, View represents the page design code and the Controller for navigational code. All these together makes Struts an essential framework for building Java applications. But with the development of new and lightweight MVC based framworks like Spring, Stripes and Tapestry, it becomes necessary to modify the Struts framework. So, the team of Apache Struts and another J2EE framework, WebWork of OpenSymphony joined hand together to develop an advanced framework with all possible developing features that will make it developer and user friendly.

Strut2 contains the combined features of Struts Ti and WebWork 2 projects that advocates higher level application by using the architecture of WebWork2 with features including a plugin framework, a new API, Ajax tags etc. So the Struts communities and the WebWork team brought together several special features in WebWork2 to make it more advance in the Open Source world. Later the name of WebWork2 has changed to Struts2. Hence, Apache Strut 2 is a dynamic, extensible framework for a complete application development from building, deploying and maintaining.