package com.action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport {
public static final String MESSAGE="Start runing !!";
public String execute() throws Exception
{
this.setMessage(MESSAGE);
return SUCCESS;
}
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h2><s:property value="message"/></h2>
</body>
</html>
<?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="struts2" extends="struts-default">
<action name="HelloWorld" class="com.action.HelloWorld">
<result name="success">/helloworld.jsp</result>
</action>
<!-- Add your actions here -->
</package>
</struts>
package com.test.action;
import com.action.HelloWorld;
import com.opensymphony.xwork2.ActionSupport;
import junit.framework.TestCase;
public class HelloWorldTest extends TestCase {
@SuppressWarnings("static-access")
public void testHelloWorld() throws Exception{
HelloWorld helloworld=new HelloWorld();
String result=helloworld.execute();
this.assertTrue("expected a success result", ActionSupport.SUCCESS.equals(result));
this.assertTrue("expected the default message!", HelloWorld.MESSAGE.equals(helloworld.getMessage()));
}
}