Struts 2 running hello world application

            Simple Hello world example to show how to run a struts 2 application in eclipse and tomcat

Step 1:

    Create an html file and design a simple form using struts tag lib

<%@ taglib prefix="s" uri="/struts-tags"%> 
		<u>Struts2 Hello World Example</u>
	<s:form action="hello" >
		<s:textfield name="uname"  label="Enter Username"/>
		<s:password name="pass" label="Enter Password" />
		<s:submit value="Sign In" align="center" />


Step 2:

Configure your web.xml file to map all request to Struts built in filter StrutsPrepareAndExecuteFilter 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
	xmlns="" xmlns:web=""
	id="WebApp_ID" version="2.5">




Step 3:

Create struts.xml file in src directory(default location to keep your struts configuration file)

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

	<package name="default" extends="struts-default">			
		<action name="hello" class="com.candidjava.controller.HelloWorld">		
			<result name="success">/success.jsp</result>			

Step 4:

Create an Controller class that extends ActionSupport and override execute method init.

package com.candidjava.controller;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport{	
	private static final long serialVersionUID = 1L;
	private String uname;
	private String pass;

	public String getUname() { 
		return uname;  

	public void setUname(String uname) {
		this.uname = uname;
	public String getPass() {
		return pass;

	public void setPass(String pass) {
		this.pass = pass;

	public String execute()
		return "success";
Step 5
Create success.jsp file to redirect view page
<%@ taglib prefix="a" uri="/struts-tags" %>

Properties binded in Struts controller can be retrived in view pages. <br>

Welcome <b><a:property value="uname"/>,</b><br/>

Thanks for visiting





        Struts 2 hello world example war

        Struts 2 hello world example maven zip

Related Post