Thursday, June 25, 2009

Getting Started with Struts - Hello World

To get a basic knowledge and introduction about Struts 2, You can read my previous post on Struts 2, now i have planned to write a post on getting started with struts 2 for Beginners. When i started Learning Struts, as a regular thing a googled for information, but unfortunately i ended up in flustration. No site gave me fulfleged infomation on getting kick started with Struts. But i believe you could get enough information from the following article.

I prefer eclipse IDE as the best for development purpose so i have used eclipse, you could get one from eclipse.org. Coming to the topic, for writing a hello world in struts i insist you to make use of the struts-blank package, so that you need not worry about the folder structures needed to follow in the framework. On understanding the first program you can get familiar with those thing. Download the Struts-Blank package, in this link you could find lots of distribution, But don't get confused with that. Choose the latest stable release, its only up to you whether to download full struts or only the application(Depends on your internet Speed!!!).

Unzip the downloaded package, in that you could find a file named struts2-blank-2.1.6.war import the file in your Eclipse IDE. You could find import option in the File->import in Eclipse. On Clicking on import, You could find a dialog asking for the type of file to import, select the war file inside the web folder or simply type war in the text box. then you will be asked for the location of the war file and a project name, after finishing that list of libraries will be shown, for an hello world those libraries are not needed. So you can skip that dialog and press Finish. And thats it your project is ready to launch.

Here Goes the snap shots:



To run a J2EE project you need a server that can be either Apache or JBoss or asny other that eclipse support. You can get apache or Jboss and install it. I have used JBoss for my application but apache is the default and popular one. But configuring the servers both covers for the same procedure.In the servers tab, right click and select new->server. You will be shown a list of servers Eclipse supports.
Select the server you have installed with the correct version, and in the next screen you will be shown the port number and other information how the server is going the run. And in the next screen you can click finish and now the right click on the project name and select "Run as"->"Run on server".
For the first Time you will be asked to choose the server to run, in that dialog a server that you have configured in the last step will be shown and you can check the option "Always use this server" so that from the next you will not be asked for confirmation on server. Then Click finish in the next dialog.
The server will start and You can see your hello world running.

You can find the working and logic beind the Struts-blank2 project in my following blog.

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.