Struts2 Hello World in Eclipse

Struts2 Hello World Example in Eclipse

Below Example use struts2.3.X version

Project Structure

Strut2 Hello File Structure

—index.jsp—






Struts2 Eclipse Hello World

Welcome To Struts 2!

Hello World

 

—HelloWorld.jsp—






Hello World!

 

—web.xml—

Struts2 Eclipse Hello Worldindex.jspstruts2org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterstruts2/*

 

—struts.xml—

/index.jsp/HelloWorld.jsp

 

—HelloWorldAction.java—

package org.apache.struts.helloworld.action;

import org.apache.struts.helloworld.model.MessageStore;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	
	/**
	 * The model class that stores the message
	 * to display in the view.
	 */
	private MessageStore messageStore;
	
	/*
	 * Creates the MessageStore model object and 
	 * returns success.  The MessageStore model
	 * object will be available to the view.
	 * (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	public String execute() throws Exception {
		
		messageStore = new MessageStore() ;
		return SUCCESS;
	}

	public MessageStore getMessageStore() {
		return messageStore;
	}

	public void setMessageStore(MessageStore messageStore) {
		this.messageStore = messageStore;
	}
	
}

 

—MessageStorage.java—

package org.apache.struts.helloworld.model;


public class MessageStore {
	
	private String message;
	
	public MessageStore() {
		
		setMessage("Hello Struts User");
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

}

 

—pom.xml—

4.0.0manningHello_World_Struts2_Mvnwar0.0.1-SNAPSHOTHello_World_Struts2_MvnUTF-8Hello_World_Struts2_Mvnorg.apache.maven.pluginsmaven-compiler-plugin2.3.21.61.6org.apache.strutsstruts2-core2.3.1.2log4jlog4j1.2.14

 

—OUTPUT—

 Struts2 Hello World

 

Download Struts2 Hello Program

 

Source: http://struts.apache.org/release/2.3.x/docs/create-struts-2-web-application-using-maven-to-manage-artifacts-and-to-build-the-application.html