Struts 2 Hello World Example

In this example, we show you how to create a hello world example in Struts 2.

The following libraries or tools are used :

  • Maven 3
  • Eclipse 3.7
  • Struts 2.3.1.2

1. Final project structure

Let review the final project structure of this tutorial, in case you get lost in later steps.

struts2 foder structure

2. Struts2 dependencies

Use Maven to download the entire Struts2 dependencies. Add “struts2-core” in pom.xml.

File : pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
        http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.mkyong.common</groupId>
	<artifactId>Struts2Example</artifactId>
	<packaging>war</packaging>
	<version>com.mkyong.common</version>
	<name>Struts2Example Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-core</artifactId>
			<version>2.3.1.2</version>
		</dependency>
	</dependencies>
	<build>
		<finalName>Struts2Example</finalName>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

3. Convert to Eclipse project

Compile and convert the to Eclipse web project in command prompt :

mvn eclipse:eclipse -Dwtpversion=2.0

Review the Eclipse .classpath file, the following Struts2 dependencies are downloaded :

File : .classpath

<classpath>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="var" path="M2_REPO/asm/asm/3.3/asm-3.3.jar"/>
  <classpathentry kind="var" path="M2_REPO/asm/asm-commons/3.3/asm-commons-3.3.jar"/>
  <classpathentry kind="var" path="M2_REPO/asm/asm-tree/3.3/asm-tree-3.3.jar"/>
  <classpathentry kind="var" path="M2_REPO/commons-fileupload/commons-fileupload/1.2.2/commons-fileupload-1.2.2.jar" />
  <classpathentry kind="var" path="M2_REPO/commons-io/commons-io/2.0.1/commons-io-2.0.1.jar"/>
  <classpathentry kind="var" path="M2_REPO/commons-lang/commons-lang/2.5/commons-lang-2.5.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/freemarker/freemarker/2.3.18/freemarker-2.3.18.jar"/>
  <classpathentry kind="var" path="M2_REPO/javassist/javassist/3.11.0.GA/javassist-3.11.0.GA.jar"/>
  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
  <classpathentry kind="var" path="M2_REPO/ognl/ognl/3.0.4/ognl-3.0.4.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/apache/struts/struts2-core/2.3.1.2/struts2-core-2.3.1.2.jar"/>
  <classpathentry kind="lib" path="C:/Program Files/Java/jdk1.6.0_13/lib/tools.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/apache/struts/xwork/xwork-core/2.3.1.2/xwork-core-2.3.1.2.jar"/>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>

4. JSP view pages

A JSP login page to use the Struts 2 tags to display username and password input fields and submit button.

Fie : login.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head></head>
<body>
	<h1>Struts 2 Hello World Example</h1>
 
	<s:form action="Welcome">
		<s:textfield name="username" label="Username" />
		<s:password name="password" label="Password" />
		<s:submit />
	</s:form>
 
</body>
</html>

File : welcome_user.jsp – A JSP view page to display a welcome message to user.

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head></head>
<body>
	<h1>Struts 2 Hello World Example</h1>
 
	<h2>
		Hello
		<s:property value="username" />
	</h2>
 
</body>
</html>

Both Struts 1 and Struts 2 has very similar UI tags syntax, just a little different in term of naming the HTML elements, for example :

Struts 1

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html:form action="Welcome">
   <html:text property="username"/>
</html:form>

Struts 2

<%@ taglib prefix="s" uri="/struts-tags" %>
<s:form action="Welcome">
	<s:textfield name="username" label="Username"/>
</s:form>

5. Action, put all business logic here

A simple Struts2 Action class, it’s used to declared all the business logic inside.

File : WelcomeUserAction.java

package com.mkyong.user.action;
 
public class WelcomeUserAction{
 
	private String username;
 
	public String getUsername() {
		return username;
	}
 
	public void setUsername(String username) {
		this.username = username;
	}
 
	// all struts logic here
	public String execute() {
 
		return "SUCCESS";
 
	}
}

In Struts2, the Action class is not required to implement any interface or extend any class, but it’s required to create an execute() method to put all the business logic inside and return a String value to tell user where to redirect.

Note
You may see some users implement the com.opensymphony.xwork2.Action class, but it’s totally optional, because the com.opensymphony.xwork2.Action is just provide some handy constant values only.
Note
Struts1’s Action class is required to extends the org.apache.struts.action.Action. But Struts 2 Action class is optional, but you are still allow to implement the com.opensymphony.xwork2.Action for some handy constant values or extends the com.opensymphony.xwork2.ActionSupport for some common default Action implementation functions.

5. Struts configuration file

A Strut configuration file to link all stuff together. The xml file name must be “struts.xml”.

File : struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
 
<struts>
 
	<package name="user" namespace="/User" extends="struts-default">
		<action name="Login">
			<result>pages/login.jsp</result>
		</action>
		<action name="Welcome" class="com.mkyong.user.action.WelcomeUserAction">
			<result name="SUCCESS">pages/welcome_user.jsp</result>
		</action>
	</package>
 
</struts>

Declare a package and warp the action classes inside, the action classes are self-explanatory, but you may interest at following new tag :

1. package name=”user”
Just a package name, don’t really care about it.

2. namespace=”/User”
It’s used to match the “/User” URL pattern. See this article – Struts 2 namespace example and explanation.

Note
Actually, the Struts2 Namespaces is equivalent to Struts 1 multiple modules

3. extends=”struts-default”
It means the package is extends the struts-default package components and interceptors, which is declared in the struts-default.xml file, located at the root of the struts2-core.jar file.

6. web.xml

Configure the Web Application Deployment Descriptor (web.xml) file to integrate Struts2 to your web project.

File web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 
<web-app>
	<display-name>Struts 2 Web Application</display-name>
 
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
                org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
                </filter-class>
	</filter>
 
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
 
</web-app>

7. Run it

In Struts2, you can access the action class directly with a suffix of .action.

http://localhost:8080/Struts2Example/User/Login.action

struts2 hello world example1

http://localhost:8080/Struts2Example/User/Welcome.action

struts2 hello world example2

Download It

Download it – Struts2-Hello-World-Example.zip (7 KB)
Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

  • Hamma

    Thanks for short and sweet tutorials.

  • Himalay Majumdar

    Just want to point out that name of “struts.xml”? is case sensitive. It won’t accept “Struts.xml” at least.

    • gg

      yup

  • http://www.discountjp.com/ ?? seiko

    ????

  • suressh

    Hi Mkyoung!

    May i know the steps to create struts 2 project using maven.

  • Anonymous

    Posting the working struts.xml. Also changed the jsps to be directly under webapp

    source code

    login.jsp

    welcome_user.jsp

  • Anonymous

    I got this working by putting the jsps directly under the webapp folder and changing the struts.xml as follows :

    login.jsp

    welcome_user.jsp

  • prasad

    How to Host struts web application in FTP Server like Hostable.com

    • http://ummestesimon.wordpress.com Efrain

      I think you should look at other side, I mean, for a Java web application (Struts or not) you’ll need a host service that supports a Java Enterprise Application container a Servlet container at least, such as Tomcat, Glassfish, JBoss, etc.

      Often applications developed in Java are meant for enterprise, so is the company the one who has all the infrastructure. However, you can find Java EE hosting services, probably Heroku could offer what you are looking for.

      Regards,
      Efrain

  • http://www.sayisalloto.ws/ Say_sal

    Hi to all, it’s truly a nice for me to pay a quick visit this web site, it contains valuable Information.

  • http://largus-wiki.ru/index.php/%D0%A3%D1%87%D0%B0%D1%81%D1%82%D0%BD%D0%B8%D0%BA:Lorrie156 ski holiday

    Hey very nice web site!! Guy .. Beautiful .. Wonderful ..
    I will bookmark your website and take the feeds
    additionally? I am glad to find so many helpful information here in the submit, we need work out
    more techniques on this regard, thanks for sharing.
    . . . . .

  • http://www.teachertube.com/view_channel.php?user=city1turkey Mohammed

    Our closest celestial neighbor does not get must respect among astronomers.
    Riders with a skiing background have a tendency to
    try to face the boat, this will often lead to a face plant as they
    catch or drop their front edge. I also came across an interesting food pairing article – Food
    Pairing Ideas for Lager Beer – in case you actually want some food
    with your lager.

  • Eve

    Hi myyong,

    I followed the instruction steps by steps. Then I encounter the error:

    com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
    WARNING: Could not find action or result
    There is no Action mapped for namespace [/] and action name [] associated with context path []. – [unknown location]

    I double checked that there is no spelling errors or configuration errors in the project.
    Beside, if the web app is built on struts 2 individually without GAE, it works fine.

    Could you help me solve this problem?
    Thanks in advance,
    Eve

  • http://gazeteoku.ws/ gazete oku

    Nice blog here! Also your web site rather a lot up fast!
    What host are you the usage of? Can I am getting your affiliate link
    to your host? I wish my site loaded up as fast as yours lol

  • http://www.ro-obermeyer.de/author/WilmaSteg http://www.ro-obermeyer.de/

    Thank you, I’ve recently been looking for info approximately this topic for ages and yours is the best I have came upon till now. However, what about the conclusion? Are you sure in regards to the supply?

  • http://naturalanxietyremediestips.com/anxiety-panic-attacks-natural-anxiety-remedies/ naturalanxietyremediestips.com

    Quality content is the key to attract the viewers to go
    to see the site, that’s what this web site is providing.

  • http://affordablesearchengineoptimizationx.com/?p=19 seo

    Are you able to guidebook me personally on your internet marketer or even the guy which deals with your website, I’d like to determine if it would be easy to be described as a invitee poster.

  • Roger

    Hello mkyoung,

    I went through tutorials on hibernate. Thank you.

    This tutorial is a big blank. How to create directory structure is not included here.

    The struts 1 tutorial does not work either. Must be too old a version of eclipse etc. cannot get running. Anyway I have no found struts 1 or struts 2 tutorial to be successful.

    The attached example may work yet the tutorial does not help to create like the attached example.

    Thank you.

  • http://www.topkek.net/category/vizyondakiler Vizyondaki Filmler

    For the reason that the admin of this web page is working,
    no doubt very rapidly it will be renowned, due to its feature contents.

  • http://www.wondershare.com/mobile-phone/pictures-from-android-to-iphone.html How to Transfer Pictures from Android to iPhone

    This design is steller! You certainly know how to
    keep a reader entertained. Between your wit and your videos,
    I was almost moved to start my own blog (well, almost.
    ..HaHa!) Great job. I really enjoyed what you had to say, and more than that, how you presented it.
    Too cool!

  • http://lasmejoresadivinanzas.bligoo.es/ Todo tipo de adivinanzas

    Thanks , I have just been searching for information about this topic
    for a while and yours is the greatest I have found
    out so far. However, what about the conclusion? Are you certain about the supply?

  • http://www.guzeloyunlar.tv.tr Anonymous

    Howdy! I just wish to offer you a big thumbs up for the excellent info you have
    got right here on this post. I am coming back to your blog for more soon.

  • http://battlefield3hacks.blog.com/ Battlefield 3 hacks And cheats

    Good day very nice blog!! Guy .. Excellent .. Amazing .
    . I will bookmark your blog and take the feeds additionally?

    I’m glad to find a lot of useful information here in the post, we’d like develop
    more techniques on this regard, thanks for sharing. . . .
    . .

  • http://www.freelanceprogrammerindia.com vinodh

    Hi,
    I am a j2ee programmer for more than a decade. explanation are precise and easy to learn. this is one of the best site for java,j2ee learning .
    thanks a lot.
    regards
    vinodh

  • dhagej

    Hi,

    I tried to deploy the provided example in jboss as 7.1, it deploys without any errors, however while trying to access I get

    Not found
    The requested URL /Struts2Example/User/Login.action was not found on this server

    I did not make any change to the application prior deploying.

  • http://switchingtoiphone5.webstarts.com/?r=20121220054214 Costs when switching to iPhone 5

    I just couldn’t depart your web site before suggesting that I actually enjoyed the standard info an individual supply to your visitors? Is gonna be again steadily in order to check up on new posts

  • gangadhar

    SEVERE: Exception starting filter struts2
    java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:256)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
    at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:103)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    at java.lang.Thread.run(Thread.java:619)
    5 Dec, 2012 8:49:15 PM org.apache.catalina.core.StandardContext startInternal
    SEVERE: Error filterStart

    iam using Eclipse these are the errors any one can solve these problem please

    • gangadhar

      reply please

    • suresh

      May be you missed to deploy struts2-core.jar in the server. Check in the lib folder of your application.

  • suresh thammina

    Conceptually very clear!

  • Meena

    Hi friends

    I download the source code , imported in eclipse ,deployed in tomcat and i run by the link
    http://localhost:8080/Struts2Example/User/Login.action.

    I got the error “Unable to load configuration. – action – file:/C:/Users/MEENA/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Struts2Example/WEB-INF/classes/struts.xml:12:75″

    pls help me to solve this.

    Thanks
    meena

  • Nitin

    After doing maven build I can’t see the lib folder inside WEBINF folder. ? why so?

    • jfabian

      Hi Nitin,

      Remenber maven look for the all the libraries that are supposed to be on WEB-INF/lib on the directory you configured for Maven respository, for example mine is:

      /home/jfabian/maven_repo

  • vivek

    We are using httpRequest, httpResponse and form beans to get the data from jsp page to the action class. How we are doing the same in struts2?
    Thanks in advance.

  • peterwkc

    Hi, I tried to follow this tutorial but when i click the submit button, it had exception at below:

    [org.apache.struts2.dispatcher.Dispatcher] Could not find action or result: No result defined for action com.peter.action.LoginAction and result success

    There is deployment error:

    ERROR [com.opensymphony.xwork2.util.finder.ClassFinder] (MSC service thread 1-2) Unable to read class [WEB-INF.classes.com.peter.action.LoginAction]: Could not load WEB-INF/classes/com/peter/action/LoginAction.class – [unknown location]
    at com.opensymphony.xwork2.util.finder.ClassFinder.readClassDef(ClassFinder.java:785) [xwork-core-2.3.1.2.jar:2.3.1.2]

  • Pingback: Maven ????????eclipse+maven2+jetty? | testing???()

  • sujit

    I have created this using default package. I am getting following error when i click on submit button.

    HTTP Status 404 – There is no Action mapped for namespace [/] and action name [Welcome] associated with context path [/StrutsLogin].

    ——————————————————————————–

    type Status report

    message There is no Action mapped for namespace [/] and action name [Welcome] associated with context path [/StrutsLogin].

    description The requested resource (There is no Action mapped for namespace [/] and action name [Welcome] associated with context path [/StrutsLogin].) is not available.

    ——————————————————————————–

    Apache Tomcat/7.0.12

    • Arpit

      same problem here.. Plz help me Mkyong sir..

      • twinkle

        The struts.xml configuration file needs to be on the classpath (as opposed to in WEB-INF).

        The linked tutorial assumes a Maven build and states the struts.xml file should go in src/main/resources, which will be included in the classpath in Maven builds. Since you’re ignoring that part, you’ll likely want to put it in the root of your source directory.

    • sumit lumar

      match the name of action in login.jsp and matched with the action name and action class…(in src file of ur project this class will be available…) match the spelling properly..clean the project stop server run again…

    • devi

      The struts.xml configuration file needs to be on the classpath (as opposed to in WEB-INF).

      The linked tutorial assumes a Maven build and states the struts.xml file should go in src/main/resources, which will be included in the classpath in Maven builds. Since you’re ignoring that part, you’ll likely want to put it in the root of your source directory.

  • Luis

    Thanks!
    Great post, just copy paste and it’s working.

  • rupen

    D:\>mvn eclipse:eclipse -Dwtpversion=2.0
    [INFO] Scanning for projects…
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    compiler-plugin/2.3.2/maven-compiler-plugin-2.3.2.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-compiler-plugin:2.3.2: Plugin org.apache.maven.plugins:maven-compiler-plugin:2
    .3.2 or one of its dependencies could not be resolved: Failed to read artifact d
    escriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:2.3.2
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-clean-plugin:2.4.1: Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 o
    r one of its dependencies could not be resolved: Failed to read artifact descrip
    tor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    install-plugin/2.3.1/maven-install-plugin-2.3.1.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-install-plugin:2.3.1: Plugin org.apache.maven.plugins:maven-install-plugin:2.3
    .1 or one of its dependencies could not be resolved: Failed to read artifact des
    criptor for org.apache.maven.plugins:maven-install-plugin:jar:2.3.1
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    resources-plugin/2.5/maven-resources-plugin-2.5.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-resources-plugin:2.5: Plugin org.apache.maven.plugins:maven-resources-plugin:2
    .5 or one of its dependencies could not be resolved: Failed to read artifact des
    criptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    surefire-plugin/2.10/maven-surefire-plugin-2.10.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-surefire-plugin:2.10: Plugin org.apache.maven.plugins:maven-surefire-plugin:2.
    10 or one of its dependencies could not be resolved: Failed to read artifact des
    criptor for org.apache.maven.plugins:maven-surefire-plugin:jar:2.10
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    war-plugin/2.1.1/maven-war-plugin-2.1.1.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-war-plugin:2.1.1: Plugin org.apache.maven.plugins:maven-war-plugin:2.1.1 or on
    e of its dependencies could not be resolved: Failed to read artifact descriptor
    for org.apache.maven.plugins:maven-war-plugin:jar:2.1.1
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    deploy-plugin/2.7/maven-deploy-plugin-2.7.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-deploy-plugin:2.7: Plugin org.apache.maven.plugins:maven-deploy-plugin:2.7 or
    one of its dependencies could not be resolved: Failed to read artifact descripto
    r for org.apache.maven.plugins:maven-deploy-plugin:jar:2.7
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    site-plugin/3.0/maven-site-plugin-3.0.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-site-plugin:3.0: Plugin org.apache.maven.plugins:maven-site-plugin:3.0 or one
    of its dependencies could not be resolved: Failed to read artifact descriptor fo
    r org.apache.maven.plugins:maven-site-plugin:jar:3.0
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    antrun-plugin/1.3/maven-antrun-plugin-1.3.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-antrun-plugin:1.3: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.3 or
    one of its dependencies could not be resolved: Failed to read artifact descripto
    r for org.apache.maven.plugins:maven-antrun-plugin:jar:1.3
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    assembly-plugin/2.2-beta-5/maven-assembly-plugin-2.2-beta-5.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-assembly-plugin:2.2-beta-5: Plugin org.apache.maven.plugins:maven-assembly-plu
    gin:2.2-beta-5 or one of its dependencies could not be resolved: Failed to read
    artifact descriptor for org.apache.maven.plugins:maven-assembly-plugin:jar:2.2-b
    eta-5
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    dependency-plugin/2.1/maven-dependency-plugin-2.1.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-dependency-plugin:2.1: Plugin org.apache.maven.plugins:maven-dependency-plugin
    :2.1 or one of its dependencies could not be resolved: Failed to read artifact d
    escriptor for org.apache.maven.plugins:maven-dependency-plugin:jar:2.1
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    release-plugin/2.0/maven-release-plugin-2.0.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-release-plugin:2.0: Plugin org.apache.maven.plugins:maven-release-plugin:2.0 o
    r one of its dependencies could not be resolved: Failed to read artifact descrip
    tor for org.apache.maven.plugins:maven-release-plugin:jar:2.0
    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    metadata.xml
    Downloading: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadat
    a.xml
    [WARNING] Could not transfer metadata org.apache.maven.plugins/maven-metadata.xm
    l from/to central (http://repo.maven.apache.org/maven2): Connection to http://re
    po.maven.apache.org refused
    [WARNING] Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/
    to central (http://repo.maven.apache.org/maven2): Connection to http://repo.mave
    n.apache.org refused
    [WARNING] Failure to transfer org.apache.maven.plugins/maven-metadata.xml from h
    ttp://repo.maven.apache.org/maven2 was cached in the local repository, resolutio
    n will not be reattempted until the update interval of central has elapsed or up
    dates are forced. Original error: Could not transfer metadata org.apache.maven.p
    lugins/maven-metadata.xml from/to central (http://repo.maven.apache.org/maven2):
    Connection to http://repo.maven.apache.org refused
    [WARNING] Failure to transfer org.codehaus.mojo/maven-metadata.xml from http://r
    epo.maven.apache.org/maven2 was cached in the local repository, resolution will
    not be reattempted until the update interval of central has elapsed or updates a
    re forced. Original error: Could not transfer metadata org.codehaus.mojo/maven-m
    etadata.xml from/to central (http://repo.maven.apache.org/maven2): Connection to
    http://repo.maven.apache.org refused
    [INFO] ————————————————————————
    [INFO] BUILD FAILURE
    [INFO] ————————————————————————
    [INFO] Total time: 9:11.471s
    [INFO] Finished at: Wed Jun 27 14:59:01 IST 2012
    [INFO] Final Memory: 2M/15M
    [INFO] ————————————————————————
    [ERROR] No plugin found for prefix ‘eclipse’ in the current project and in the p
    lugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the re
    positories [local (D:\.\path\to\local\repo), central (http://repo.maven.apache.o
    rg/maven2)] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
    ch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please rea
    d the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundF
    orPrefixException

    I got this errors.

  • Pingback: Google App Engine + Struts 2 example()

  • Tapan

    hey mkyong,
    nice article and really help me a lot, i have quike question, suppose if i wants to

    add one more file say DBConnectivity.xml in ‘resource’ folder and this file contains

    details of my Database like username/pwd etc, DBConnectivity.xml is read/import by ‘ApplicationContext.xml, which exist in ‘WEB-INF’ folder, how can i give path to it

    cause when i m trying to give “resources/DataSource.xml” it always give ‘file not

    found exception’ cause its trying to find in ‘WEB-INF/resources/DataSource.xml’

    folder, which is wrong. How can i do that. can you please help me for this. Actually i

    am stuck now :-)
    Thanks.

    • http://www.mkyong.com mkyong

      Not really related with above article, please post your question on JavaNullPointer.com? And elaborate more about your problem, some source code will be more helpful.

  • Andres

    Hi!! I’m having the problem that can’t found the struts-tags library, i’m not using mavem, i just import all struts library into my project.

    The Exception is :

    org.apache.jasper.JasperException: /index.jsp(2,41) Archive JSP “/struts-tags” not found

  • Andres

    Hi!!! i’m having this problem :

    org.apache.jasper.JasperException: /index.jsp(2,41) Archive JSP “/struts-tags” not found

    • http://www.mkyong.com NirmalaGanesan

      sorry..i don know..

    • Githin

      make sure all jar files are inside the lib

      double check taglib directive uri

    • gopi

      i think you have problem with versions of taglibs@andress

  • Pingback: How to use mkyong tutorial()

  • Doku

    Mykong thanks for the tutorial

    I wish if you have gone a few steps in details as for how to run it in the eclipse the project or how to deploy it in(Tomcat or JBOSS), there would not have any questions.

    • kasabian

      Hi Mkyong!
      I have a question for you, and please answer me :D
      how to deploy this tutorial in Tomcat with create simple project Tomcat??
      I’m a beginner and try to understand how struts to work. Help me please!

      • http://www.mkyong.com mkyong

        Just published a guide to show users how to use mkyong tutorial, hope it help.

  • AW

    I am trying to deploy on JBoss SOA platform
    Failed in deployment with error in the log file

    2011-12-13 17:21:36,990 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/Struts2ExampleHelloWorld]] (HDScanner) Exception starting filter struts2
    java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

    commons-fileupload-1.2.2.jar
    commons-io-2.0.1.jar
    commons-logging-1.1.1.jar
    freemaker-2.3.16.jar
    JRE 1.6
    Junit 3
    ognl-3.0.1.jar
    spring-test-2.5.6.jar
    struts-core-2.3.3.1.jar
    xword-core-2.2.3.1.jar

    Only file change in your example is the version number of

     
    &lt;dependency&gt;
          &lt;groupId&gt;org.apache.struts&lt;/groupId&gt;
    	  &lt;artifactId&gt;struts2-core&lt;/artifactId&gt;
    	  &lt;version&gt;2.2.3.1&lt;/version&gt;
        &lt;/dependency&gt;

    Anything related to my JBoss setting?

    • http://www.mkyong.com mkyong

      if you revert back to Struts2 version 2.1.8, can it be deploy?

      • AW

        Now I used Struts2 version 2.1.8

        and use the following the build the project

        commons-fileupload-1.2.1.jar
        commons-io-1.3.2.jar
        commons-logging-1.0.4.jar
        freemaker-2.3.15.jar
        JRE 1.6
        Junit 3
        ognl-2.7.3.jar
        spring-test-2.5.6.jar
        struts2-core-2.1.8.jar
        xwork-core-2.1.6.jar

        + Created WEB-INF/lib and copied all above to the directory

        I was able to deploy to JBOSS SOA platform and run the example.

        However, why the example failed in Struts2 version 2.2.3.1?

        • http://www.mkyong.com mkyong

          Didn’t try Struts 2.2.3.1, may be the dependency is move into another jar, which you need to identify manually.

  • http://jigarshah.net Jigar Shah

    Hi mkyong,
    Thanks for such simple and to-the-point tutorials.

    I am trying above example with few difference.
    1. Struts version 2.2.3.1
    2. As my company says, keep jsp in WEB-INF – I moved User folder to WEB-INF/content/
    3. I am using convention plugin too. (I think its bundled with struts ? i have tht in dependency in maven)

    As per another tutorial of urs, convention pplugin will always look at /WEB-INF/content directory. So if i specify namespace as u said, it should work ? It does not.

    If i move out User directory to webapp, It works fine. What am I missing here ?

    Just on side note, I am using jetty plugin of mvn to run locally. mvn jetty:run

    war structure tht does not work,
    -example.war
    — WEB-INF
    —content
    —-User
    —–login.jsp
    —–welcome_user.jsp

  • salman

    Hi Mr Young,

    is there an eclipse plugin for struts available is the market?

    Thanks

  • Ted

    Hey I am trying to run this code but I cannot do it… I am new to Maven also. I imported this project into Eclipse and my Maven is ready and running. How do I compile it and put it into Tomcat?

    Thanks!

  • Sarit Kumar Si

    I am a beginner using Struts 2.0. I am facing the “There is no Action mapped for namespace / and action name “display” ” problem. This is on eclipse IDE using Tomcat 6.0 server.Please help. The code is as follows:

    Welcome.jsp

    Welcome

    Generate.jsp

    Insert title here

    Welcome,

    Web.xml

    HelloWorld

    Welcome.jsp

    Struts2
    org.apache.struts2.dispatcher.FilterDispatcher

    Struts2
    /*

    UserNameAction.java

    package demo_package;

    import com.opensymphony.xwork2.ActionSupport;

    public class UserNameAction extends ActionSupport{

    private String name;
    public String execute() throws Exception{
    setName(“Hii”);
    return SUCCESS;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }

    }

    struts.xml

    Generate.jsp

    jar files

    commons-beanutils-1.8.0.jar
    commons-digester-1.8.jar
    commons-logging-api-1.1.jar
    commons-validator-1.3.0.jar
    freemarker-2.3.8.jar
    ognl-2.6.11.jar
    struts2-core-2.0.12.jar
    struts2-tiles-plugin-2.0.12.jar
    tiles-api-2.0.4.jar
    tiles-core-2.0.4.jar
    tiles-jsp-2.0.4.jar
    xwork-2.0.6.jar

    • http://www.mkyong.com mkyong

      contact me, and send me your code for debugging

    • christopher

      use struts2-core-2.1.8 and use latest xwork jar

    • devi

      Even I had the same problem. So here is the solution which I got it from some other blog.

      <>

      Hope it helps!

  • kiranmayi

    iam developing struts2 application with xml validation framework.
    if i didnt enter any input from my login page with action like
    “http://localhost:8080/TALKTACIT_NEW/admin/adminLogin.action”

    it gives the same page with action error page . But if i sent the input again from this page the action becomes

    http://localhost:8080/TALKTACIT_NEW/admin/admin/adminLogin.action

    that is in first admin/adminLogin.action and in second tim admin/admin/adminLogin.action is generating

  • Pingback: Struts 2 Tutorials()

  • DineshT

    I am newbie for struts2 framework,
    i had tried sample applications with struts1 framework
    But with framework 2 i am unable to do a simple application
    due to the configuration pbm,
    Can somebody help me in the configuration area of struts2?

    Thanks in advance

    • http://www.mkyong.com mkyong

      What’s your problem? Is the attached example not working?

      • jfabian

        Hi mkyoung!

        I did everything, step by step, and when running it just doesn’t work. I also download your source code, and imported to my workspace and it happens the same problem, I get an Http Status 404. Maybe there’s something you skipped or any other steps that may help me.
        What can I do to try to fix it ?

  • Pingback: Struts 2 Hello World Annotation Example()