“Hello, World” Web Application using Struts 2 in NetBeans IDE 6.1
This tutorial guides you through the process of creating and running a basic “Hello, World” Struts 2 web application using the NetBeans IDE 6.1.
NOTE: I recommend trying to follow the NetBeans tutorial on the Struts 2 website first. If you find any problems following it, then come back to my tutorial. I have tried to make this more beginner friendly by including a lot of screenshots.
Download/Install Java SE, NetBeans and Struts 2
- Download and Install the latest version of Sun JDK: Sun Java SE 6 Update 7.
- Download and Install the latest version of NetBeans IDE: NetBeans IDE 6.1.
- Download the Struts 2 “Full Distribution” package(~90MB) and extract it in a directory. You can also opt for the smaller “Essential Dependencies Only” package if you want to later incrementally add additional packages as and when the need arises.
- Run the NetBeans IDE and create a new Web Application project in it. Name it “HelloStruts2World” or something like that.

Don’t select any frameworks, especially Struts 1.2.9, to be added to the project.
Add Struts 2 Libraries to Web Application project in NetBeans and configure web.xml file
- Add the Struts 2 library files to the web application project: Expand the web application project structure in the Project pane if not already expanded; right-click on the Libraries folder and click the Add JAR/Folder… menu item.

In the Add JAR/Folder file chooser dialog box, browse to the extracted Struts 2 directory, go to lib directory in it and select all the JAR files that you want to add to the project. Hold down the Ctrl button to select multiple files.

The following JAR library files are essential for most Struts 2 projects(and for this tutorial) but you can select more if you know that you need them(you can add additional libraries later also):
- commons-logging
- ognl
- struts2-core
- xwork
- freemarker
Libraries folder in your project will now look like this:

- Add a filter element to web.xml deployment descriptor to let Struts 2 handle all the requests for your web application. Expand the Configuration Files folder and double-click on web.xml file, select the XML tab and copy paste the following code in it.
[xml]
Struts 2 filter
org.apache.struts2.dispatcher.FilterDispatcher
Struts 2 filter
/*
30
[/xml]You can enter the same data in Filters tab also:
Create Struts 2 action Java class and JSP result page and configure struts.xml file
- We need one or more Java packages to store all the Java classes(Struts 2 actions) in it. Let’s call the first package “hello.” Right click Sources Package directory, select New and then select Java Class… menu item. Enter a name for the Java class(say HelloStruts2World”) and enter a package name(say hello) and click Finish.
- Edit the HelloStruts2World.java file so that it looks like this:
[java]
package hello;
import com.opensymphony.xwork2.ActionSupport;public class HelloStruts2World extends ActionSupport {
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}private String message;
public String getMessage() {
return message;
}@Override
public String execute() {
message = “Hello, ” + userName + “.”;
return SUCCESS;
}
}
[/java] - We now need to configure the Java class created in the above step as a Struts 2 Action and map it to a result page. To do so, we need to create two Struts 2 configuration files – struts.xml and struts.properties – in the source package.
- Right-click on hello package in Source Packages folder and select New and then select XML document… and enter struts as the file name. This will create struts.xml file.
- Right-click on hello package in Source Packages folder and select New and then select Properties File… and enter struts as the file name. This will create struts.properties file.
Edit struts.xml file such that it has the following content:
[xml]
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
/index.jsp
[/xml]This maps the requests sent to the “/HelloStruts2World.action” url to HelloStruts2World.java Struts 2 action and after the successful execution of the request, it gets directed to the index.jsp result page. Leave the struts.properties file empty for now.
- Let us access the message property set by HelloStruts2World action and display it in the index.jsp page. Edit index.jsp so that it looks like this:
[html]
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
"http://www.w3.org/TR/html4/loose.dtd">
Hello World!
Struts 2 Message:
Enter your name:
[/html]
Run the Struts 2 Web Application Project in NetBeans 6.1 IDE
- The “HelloStruts2World” web application project structure, when relevant folders expanded, should look like this:

- Run the web application by going to Run -> Run Main Project and then access the following URL in a web browser: http://localhost:8080/HelloStruts2World/. You may have to modify this URL depending on what port the web server is running(“8080″) and what is the name of your web application(“HelloStruts2World”).
Other Options:
This is the manual way to develop Struts 2 web applications in the NetBeans IDE but it is at least more beginner friendly than working from the command line using just the Maven build tool. There is a Struts 2 plugin called nbstruts available for NetBeans; its functionality is currently limited but it is under active development. Other popular alternative IDEs for developing web applications using Struts 2 are Eclipse and IntelliJ IDEA.
[...] Java, Netbeans, struts2 — tabrez @ 10:09 pm As mentioned in my previous post about creating Struts 2 web applications in NetBeans IDE, there is a Struts 2 plugin available for the NetBeans IDE but it is still under development. You [...]
Good Forum for Learners.
[...] experience with NetBeans or Eclipse IDEs even with the help of the plugins: see my previous posts “Hello, World†Web Application using Struts 2 in NetBeans IDE 6.1 and Struts 2 Plugin for NetBeans IDE – nbstruts2support for example. All we need to do now is to [...]
I cant not run the project!!!
Estado de HTTP 503 -
type Informe de estado
Mensaje
DescripciónEl servicio solicitado () no se encuentra disponible actualmente.
Sun Java System Application Server 9.1_02
Helpme!!!! please
instead of hello I’ve used my.strut2.hello package.
in form i use action=”my/strut2/hello/HelloStruts2World.action”, but I’m getting following exception:
java.lang.IllegalArgumentException: URI is not hierarchical
Servlet.service() for servlet jsp threw exception
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:290)
If your actions reside in the same package, you can try specifying just the action name(note that there is not .action extension):
action=”HelloStruts2World”
Hello,
I’ve followed you tutorial which run fine and displayed the hello world page, but if I write my name and then click the submit button I obtain the following error:
(FYI the url displayed is: http://localhost:8080/HelloStruts2World/hello/HelloStruts2World?userName=zaf)
error in the page HTTP Status 404
type Status report
message
descriptionThe requested resource () is not available.
and in the IDE :
under glassfish :
No configuration found for the specified action: ‘hello/HelloStruts2World’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.
Have you any idea about this problem ?
Thanks for your answer
I´m getting the same error that happened with zaf.
What i do to resolve this?
thanks
I am getting the following error:
Deployment error:
The module has not been deployed.
See the server log for details.
at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:163)
at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:104)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor166.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:277)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:460)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)
Caused by: The module has not been deployed.
at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:157)
… 16 more
BUILD FAILED (total time: 17 seconds)
Could you please advice me.
Nice tutorial on Struts Application.
A similar tutorial on struts…
Creating Struts project in Eclipse
nice tutorial for beginners
Hi!
Thanks for the tutorial.
I was getting the same error that happened with zaf and GVSOUZA.
After several hours of suffering I find the solution:
Move the struts.xml file to the web/WEB-INF folder
That’s all! :-)
I hope this can be helpful to someone.
(Sorry for my english)
i created this app in netbeans 6.5 and it didn’t work at first. The struts.xml file wasn’t getting read. So I made a ‘class’ folder in my Web-INF directory and then put the struts.xml file in there. Rebuild, reran. And it worked.
Hi, nice tutorial.
It works for me using Netbeans 6.5 and Struts 2.1.6.
I only have to include the following to the project from struts 2.1.6 directory:
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
And i place the struts.xml file on:
Source Packages directory not in the hello package.
Adding those things the project works well and please make a good code.
Its not working and i dont find the sun-web.xml file in my WEB-NF folder. Is it mandatory to have this file.
Can’t believe that such a simple example just not working!!!
as Bill MR said, dont forget to add commons-fileupload-1.2.1.jar for working, and always clean before running the project for being sure it works.
Just put the struts.xml file in source packege, then it will works fine
Thanks All
I did as you explained, compiled fine but when i try to run it looks for applicationCOntext.xml(some spring sort of error), why is it looking for spring etc.
The solution for errors in the resource are as Bill MR said, dont forget to add commons-fileupload-1.2.1.jar for working. And as Knight said,Don’f forget clean before running the project for being sure it works.
And about the spring, make sure that you don’t add it before.
i run this application on netbeans 6.0 so index page is run than i put name in textfield than occur error like
The requested resource () is not available.
so give me solution
code for struts.xml //////////////////////////
/index.jsp
index.jsp //////////////////////////////
Hello World!
Struts 2 Message:
Enter your name:
sir i run this project index page is run than i type the name in text field than submit than occured error like
The requested resource () is not available.
so sir give me help or solution
code for struts.xml /////////////////
/index.jsp
code for index.jsp //////////////////////////////
Hello World!
Struts 2 Message:
Enter your name:
we can not find problem here we tried so many ttimes
sir i run this project index page is run than i type the name in text field than submit than occured error like
The requested resource () is not available.
so sir give me help or solution
my name is khushal
[quote comment="137973"]i run this application on netbeans 6.0 so index page is run than i put name in textfield than occur error like
The requested resource () is not available.
so give me solution
code for struts.xml
//////////////////////////
/index.jsp
index.jsp //////////////////////////////
Hello World!
Struts 2 Message:
Enter your name:[/quote]
khushal
No configuration found for the specified action: ‘HelloStruts2World’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.
what is wrong between this mapping
Hello,
I’ve followed you tutorial which run fine and displayed the hello world page, but if I write my name and then click the submit button I obtain the following error:
(FYI the url displayed is: http://localhost:8080/HelloStruts2World/hello/HelloStruts2World?userName=khushal)
error in the page HTTP Status 404
type Status report
message
descriptionThe requested resource () is not available.
and in the IDE :
under glassfish :
No configuration found for the specified action: ‘hello/HelloStruts2World’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value
what do you mean, i can not understand this glassfish error
Have you any idea about this problem ?
i made so any try but i can not find solution?last five days
i made 1 application in struts2 with netbeans but got one errror like
There is no Action mapped for namespace / and action name login.
The requested resource (There is no Action mapped for namespace / and action name login.) is not available.
here give two code what is wrong between this don’t knows
1)
2)
/index.jsp
please give me acton mapping problem solution
[quote comment="137978"]No configuration found for the specified action: ‘HelloStruts2World’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.
what is wrong between this mapping[/quote]
[quote comment="137988"]i made 1 application in struts2 with netbeans but got one errror like
There is no Action mapped for namespace / and action name login.
The requested resource (There is no Action mapped for namespace / and action name login.) is not available.
here give two code what is wrong between this don’t knows
1)
2)
/index.jsp
please give me acton mapping problem solution[/quote]
thanks in advance
khushal
thanks, this articule is very good, I enjoy read it, and worked perfect ¡¡¡
Hi,
Even I encountered same issue.
But i missed out a step.
Create struts.xml in source package and strust.xml file.
It works fine now.
Regarsds,
Deepak Reddy
[quote comment="137989"][quote comment="137978"]No configuration found for the specified action: ‘HelloStruts2World’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.
what is wrong between this mapping[/quote]
[quote comment="137988"]i made 1 application in struts2 with netbeans but got one errror like
There is no Action mapped for namespace / and action name login.
The requested resource (There is no Action mapped for namespace / and action name login.) is not available.
here give two code what is wrong between this don’t knows
1)
2)
/index.jsp
please give me acton mapping problem solution[/quote]
thanks in advance
khushal[/quote]
[quote comment="138093"]Hi,
Even I encountered same issue.
But i missed out a step.
Create struts.xml in source package and strust.xml file.
It works fine now.
Regarsds,
Deepak Reddy
[quote comment="137989"][quote comment="137978"]No configuration found for the specified action: ‘HelloStruts2World’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.
what is wrong between this mapping[/quote]
[quote comment="137988"]i made 1 application in struts2 with netbeans but got one errror like
There is no Action mapped for namespace / and action name login.
The requested resource (There is no Action mapped for namespace / and action name login.) is not available.
here give two code what is wrong between this don’t knows
1)
2)
/index.jsp
please give me acton mapping problem solution[/quote]
thanks in advance
khushal[/quote][/quote]
Hi, I ‘m using netbeans 6.5 but the HTTP Status 404 – There is no Action mapped for action name HelloStruts2World is thrown after the deployment and submitting the name.pleaase help me. thanks.hve a nice day!!!
I want to know how to write program of struts using netbeans 6.5.
kindly sent som pdf on my mail. Which are easy to understand …..
Thanks a lot.
[...] II: * Tutorial – Struts-2 no NetBeans 6.5 – Novo * Tutorial – Struts-2 no NetBeans 6.1 * Start – Struts-2 – Hello World – dicas suport * Tutorial – [...]
I had the same problem with my first Struts2 application. My web folder structure was wrong … I was putting jsp folder and index.jsp inside WEB-INF … just got them out and put them at the same level as that of WEB-INF … and it’s working
i do get the same error “the requested resource is not currently available.”
i did place the strut.xml file in source package and added that commons-fileupload-1.2.1.jar but it didn’t help as it is giving the same problem.
please give a solution to this problem.
New project creation sometimes overwrites the web.xml. If you are getting the resource not found error, verify that you have the filter and filter-mapping tags present in your web.xml and that they are defined correctly.
Thank you man for this helpful tutorial .
useful