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.

No comments:

Post a Comment