1:36 pm - Saturday March 25, 2017

Struts 2 Hello world Example and Tutorial

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

 

Hello World Example and Tutorial

Jar File Structure

index.jsp

</pre>
<h4><span style="text-decoration: underline;">Struts2 hello World</span></h4>
<pre>

HelloWorld.java


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

	private String uname;

	public String getUname() {
		return uname;
	}

	public void setUname(String uname) {
		this.uname = uname;
	}

	public String execute()
	{
			return SUCCESS;
	}

}

success.jsp


Welcome <strong>,</strong>

You have been successfully executed struts 2 hello world program..

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>
    <include file="struts-default.xml"/>
    <package name="a" extends="struts-default">
        <action name="hello" class="com.candidjava.controller.helloWorld">
            <result name="success">/success.jsp</result>
        </action>
    </package>
</struts>

web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

output screenshots

                            download sourcecode+Struts2_jar

BACK



Filed in: Struts 2 Tutorial

Comments are closed.