Struts 2.x Maven showcase for Eclipse IDE

I faced problem while running Struts2 program in Eclipse. So I decided to find a solution for that though an easy solution (plugin) is available in Netbeans.

See how to configure Struts2 in Netbeans

But I want to get it running in Eclipse
There is no such plugin available of struts2 for Eclipse as there is for NetBeans.
But Struts2 can be configured in Eclipse using Maven.

According to the experts it’s an easiest starting points to get the war and then modify it according to your need

See Discussion

There is an official war file available. Follow the steps to get it running

Step 1: Install Maven using Eclipse market place or manually downloading plugin.

Step 2: Download the Struts2 war Struts2.3.14 for Eclipse

Step 3: Import downloaded war file in Eclipse

Now run the project. Enjoy!

 

Searching for Struts2.3.14 jar files? Download struts2.3.14 jar

Struts 2.x Netbeans IDE Setup

Struts 2.x is a powerful framework which is used to develop variety of web applications. It is under the control and management of Apache organization and is available as open source. It provides easy and effective way to develop web applications based on MVC pattern. It makes developers easy to work with Servlet and JSP.

To Know more or to Download Libraries visit http://struts.apache.org/

In this post We are going to learn about Struts 2.x Netbeans IDE Integration and to develop and run our first web application using Struts.

Here we will first start with Struts 2.x Netbeans IDE Integration. To perform this, We will go through a series of steps as mentioned below:

Download the following software and plugins:

1. Latest Netbeans IDE from www.netbeans.org to develop web application.

2. To get the support of struts 2.x in our Netbeans IDE We need to download some plugins for the installed netbeans version.
For Example: If you have downloaded the Netbeans IDE Version 7.2 you have to download the following plugins to get Struts 2.x support in Netbeans 7.2:
a. org-netbeans-modules-framework-xwork.nbm
b. org-netbeans-modules-web-frameworks-struts2.nbm
c. org-netbeans-modules-web-frameworks-struts2lib-v2_0_14.nbm
d. org-netbeans-modules-web-frameworks-struts2lib-v2_2_3.nbm

The plugins generally vary depending upon the Netbeans IDE versions. Visit www.netbeans.org for any information and download regarding struts 2.x plugin support for Netbeans IDE incase you have error in installing the above plugins in your installed Netbeans IDE.

3. After downloading the plugins for your Netbeans IDE install it in your IDE using the following steps:

a. Click on Tools from the menu options.
b. Click on plugins.
c. Click on downloaded option from the new popped window.
d. Select add plugins and browse through the folders to locate the plugins you have downloaded.
e. The final step is to click on install after adding all the plugins.
f. Ignore and Skip any warnings if received.
f. The IDE will be restarted on its own or will ask to restart.
g. After restarting the IDE, you are ready to develop projects using Struts 2.x framework.

Now it’s time to develop our very first program or web application in Struts using Netbeans as IDE.

1. Click on file option from menu (Menu Bar).
2. Click on New Project
3. Select Java Web. You can find it under categories list (on Left) and Web Application (on Right) in the popped window after selecting the twos click Next.
Struts Netbeans
4. After clicking on next a new window will appear or popped on the screen asking you to enter the project name and location to store the project, by default it will have some values:
Struts Netbeans
You can change the name of project or can leave it as highlighted in blue and simply click on next. Here I have stored in my custom folder on drive D. You can make changes from here or leave it as it is.
5. After clicking on Next in the above point i.e. step 4. You will get a new popped window asking for sever by default it will be having glassfish server (It depends upon the version and type of Netbeans IDE installed).
struts3
In this example (See the above screenshot), I have used Apache Tomcat Server. If you can see Glassfish Server leave as it is or in case having no server You have to download and add a server.
To download a Glassfish Server visit glassfish.java.net
After downloading it, Install it in any directory. After Successful installation using the Netbeans IDE popped up window locate and add the installed glassfish server.

After selecting the server, you can leave the rest as it is and click on next.

6. Here is the last step: You will see Struts 2 option under the Framework only in case of successful plugins integration as mentioned in the beginning of this post.
Struts Netbeans
Select Struts2 option and select create example page as shown in the screenshot. After that Click Finish.

You have successfully created the new project “WebApplication1” (As per the project name mentioned by you).

To run your first Struts 2.x web project:
Right click on “WebApplication1” under projects category on the left of window and click run.
Now you can view your web page in the browser!!

Struts 2.x Tags Examples

Struts 2.x Tags :: The form tags for easier development!

The Struts 2.x Tags can be used inside the form tag to access and provide an effective way to display action tags, radio button, checkbox, combobox, select tag, double select tags, updown select tags, date time pickers, etc.
Struts 2.x is a powerful framework which is used to develop web applications. It is under the management of apache organization and is available as open source. It provides easy and effective way to develop web applications based on MVC pattern. It makes easy to work with Servlet and JSP.
ACTION TAG:
This tag can be used to transfer the control to struts.xml and further to the action. Here in name=”test” the term within the double quotes refer to the name of action which can be found or written inside the struts.xml file.
By default the value of executeResult is false, in that case the action tag will not be executed. So
will not work if executeResult is not set to true.
We can also pass parameters within the action tag. e.g.:
oxyzium
RADIO BUTTON TAG:
This tag can be used inside a Struts 2.x form tag to get radio button select option.
CHECKBOX TAG:
This tag can be used inside a Struts 2.x form tag to get checkbox select option.
COMBOBOX TAG:
This tag can be used inside a Struts 2.x form tag to get combobox select option.
The attribute emptyOption can be set to true or false. See the effect on both changes in your program.
SELECT TAG:
This tag can be used inside a Struts 2.x form tag to get sengle/multiple select option.
The attribute multiple can be set to true or false. See the effect on both changes in your program.
DOUBLESELECT TAG:
This tag can be used inside a Struts 2.x form tag to get sengle/multiple select option.
The attribute emptyOption can be set to true or false. See the effect on both changes in your program.
UPDOWNSELECT TAG:
This tag can be used inside a Struts 2.x form tag to get sengle/multiple select in up and down direction.
DATETIMEPICKER TAG:
This tag can be used inside a Struts 2.x form tag to display date time select option.
Remember to include inside head tag to use the above tag.
Best Regards!!!

Execute and Wait Interceptors in Struts 2.x

Hello Friends,
Today, in this post you are going to know or have knowledge about “Execute and Wait Interceptors in Struts 2.x”. 
The time taken by the action, if takes a longer amount of time and We want to display or show a “waiting icon” or “some waiting message” page during this whole waiting process until action gets completed and returns true from execute() method We can use this type of interceptors.
Execute and Wait Interceptors should be placed at the bottom of the action result declaration and after any other interceptors if present or in case of default interceptor too as Execute and Wait interceptors will/can prevent other interceptors to perform their work.

@param delay : Specifies the duration after which the “wait” message page should be displayed. 

@param delaySleepInterval : Specifies the duration after which a check for action completion is made. It has default time value of 100ms.
Working Example of Execute and Wait Interceptor:

1. Create an index.jsp page
Write the following code there:

Remember: It will work for Struts 2.x Projects and make sure you have included the taglib directory of Struts 2.x in the index.jsp.

If you have not included it do it now, write the following code above HTML tag:

2. Create a welcome page e.g. welcome.jsp having A welcome message.

3. Create a jsp page which you want to show while the background process is going on e.g: wait.jsp
Write the following code there in wait.jsp

include this above title tag of page.

4. Make configurations in struts.xml

5. Create a package action and in that package create a class Call.java
Write the following code inside the Call i.e. class body there:

That’s it… You application or program is ready to provide you the the functionality to display visitors a waiting page while performing background process which generally takes time like database queries, handling registration forms, login, etc.

Best of Luck!!!

Struts 2.x Tiles Framework (Netbeans IDE) – Part 01

Struts 2.x Tiles Framework (Netbeans IDE) provide us an easy and effective way to manage our web page contents.

Struts 2.x Tiles Framework provide us to make effective and easily maintainable  websites using struts 2.x. With the use of tiles in developing web projects we are able to make and deliver changes in a particular area of page on user’s click for this we don’t need to write the whole page code on all the pages. Just what we need is to integrate our project with tiles framework.

Here is what we need to develop struts 2.x tiles based web project:

1. Create a web project : Visit this link to know “How to Start or Create a new Struts 2.x Web project?“.
2. After Successful creation of the web project. Now click on libraries option present on the left of Netbean IDE window under projects category.
3. In libraries right click on any struts 2.x libraries and in the appeared pop click remove. After doing this removal you will find that all the struts 2.x libraries will be removed.

Now, make sure you have downloaded the following jar files:

  1. commons-beanutils-1.7.0.jar
  2. commons-digester-2.0.jar
  3. commons-fileupload-1.2.2.jar
  4. commons-io-2.0.1.jar
  5. commons-lang-2.5.jar
  6. commons-logging-api-1.1.jar
  7. freemarker-2.3.16.jar
  8. javassist-3.11.0.GA.jar
  9. ognl-3.0.1.jar
  10. struts2-core-2.2.3.jar
  11. struts2-tiles-plugin-2.2.3.jar
  12. tiles-api-2.0.6.jar
  13. tiles-core-2.0.6.jar
  14. tiles-jsp-2.0.6.jar
  15. xwork-core-2.2.3.jar

Before moving ahead make sure you have downloaded all the above mentioned plugins as this plugins are required to build struts 2.x tiles based web applications.’

After you have downloaded these jar files, again right click on libraries and then select add jar files option. A new window pop ups, now locate your downloaded plugins and add all the jar files one by one or all at the same time.

Download all tiles plugins from here

Now click on your root directory and locate and open web.xml file under WEB-INF folder. Add the following code block inside …. You can add it in center-mid after the end of previous code tag and before the start of the new.
1. web.xml configuration:

org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG

/WEB-INF/tiles.xml

org.apache.struts2.tiles.StrutsTilesListener

  2. Now in the same directory where the web.xml file is present create a tiles.xml file by right clicking on WEB-INF folder -> New -> Other -> locate xml folder and select xml document from right name the document as tiles.xml and click on finish.
Add the following code after opening the tiles.xml file:
Save all files!!! Now you are ready to develop struts 2.x tiles programs.
For further information and example visit  Struts 2.x Tiles Framework (Netbeans IDE)- Part(2).