THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
First, we need a server page to present the message.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>Hello World!</title> </head> <body> <h2><s:property value="message" /></h2> </body> </html> |
Second, we need an Action class to create the message.
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
package tutorial; import com.opensymphony.xwork2.ActionSupport; public class HelloWorld extends ActionSupport { public static final String MESSAGE = "Struts is up and running ..."; public String execute() throws Exception { setMessage(MESSAGE); return SUCCESS; } private String message; public void setMessage(String message){ this.message = message; } public String getMessage() { return message; } } |
...
Edit the struts.xml
file to add the HelloWorld
mapping.
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="tutorial" extends="struts-default"> <action name="HelloWorld" class="tutorial.HelloWorld"> <result>/HelloWorld.jsp</result> </action> <!-- Add your actions here --> </package> </struts> |
...