WW-1349 Move new Tutorial code into Showcase

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@438906 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ted Nathan Husted
2006-08-31 13:10:49 +00:00
parent 6d0bb04ded
commit ad4b4c218a
12 changed files with 211 additions and 0 deletions
@@ -0,0 +1,23 @@
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
public class HelloName extends ActionSupport {
public String execute() throws Exception {
if (getName() == null || getName().length() == 0)
return ERROR;
else
return SUCCESS;
}
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,29 @@
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.ParameterAware;
import java.util.Map;
public class HelloName2 extends ActionSupport implements ParameterAware {
public static String NAME = "name";
public String execute() {
String[] name = (String[]) parameters.get(NAME);
if (name == null || name[0] == null || name[0].length() == 0)
return ERROR;
else
return SUCCESS;
}
Map parameters;
public Map getParameters() {
return parameters;
}
public void setParameters(Map parameters) {
this.parameters = parameters;
}
}
@@ -0,0 +1,23 @@
package tutorial;
import com.opensymphony.xwork2.Action;
import java.text.DateFormat;
import java.util.Date;
public class HelloWorld implements Action {
public String execute() {
message = "Hello, World!\n";
message += "The time is:\n";
message += DateFormat.getDateInstance().format(new Date());
return SUCCESS;
}
private String message;
public String getMessage() {
return message;
}
}
@@ -0,0 +1,10 @@
<html>
<head>
<title>Error Page</title>
</head>
<body>
<p>
Hmmm, you did not enter a name. Please try again!
</p>
</body>
</html>
@@ -0,0 +1,11 @@
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Success Page</title>
</head>
<body>
<p>
Hello, <s:property value="name" />!
</p>
</body>
</html>
@@ -0,0 +1,16 @@
<html>
<head>
<title>A simple HTML form with data</title>
</head>
<body>
<p>What is your name?</p>
<form action="HelloName.action" method="post">
<p><input type="text" name="name"></p>
<p><input type="submit" value="Submit your name."/></p>
</form>
</body>
</html>
@@ -0,0 +1,12 @@
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Success Page - Without Using Getters and Setters</title>
</head>
<body>
<p>
Hello, <s:property value="parameters.name"/>!
</p>
</body>
</html>
@@ -0,0 +1,16 @@
<html>
<head>
<title>A simple HTML form with data</title>
</head>
<body>
<p>What is your name?</p>
<form action="HelloName2.action" method="post">
<p><input type="text" name="name"></p>
<p><input type="submit" value="Submit your name."/></p>
</form>
</body>
</html>
@@ -0,0 +1,11 @@
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
The message generated by my first Action is:
<s:property value="message"/>
</body>
</html>
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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 Mailreader</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
<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>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
@@ -0,0 +1,10 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=Hello.action">
</head>
<body>
<p>Loading ...</p>
</body>
</html>
@@ -0,0 +1,16 @@
import junit.framework.TestCase;
/**
* An example text class to verify the configuration.
*/
public class HelloTest extends TestCase {
/**
* An example test that asserts true.
*
* @throws Exception On invalid assertions
*/
public void testHelloAction() throws Exception {
assertTrue(true);
}
}