日期:2014-05-20 浏览次数:20799 次
package tutorial; import com.opensymphony.xwork2.ActionSupport; public class HelloWorld extends ActionSupport{ private String name; public String getName(){ return name ; } public void setName(String name){ this.name = name ; } public String execute(){ name = "Hello,"+ name+"!"; return SUCCESS; } }
<!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="tutorial" extends="struts-default"> <action name="HelloWorld" class="tutorial.HelloWorld"> <result>HelloWorld.jsp</result> </action> </package> </struts>
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Say Hello</title> </head> <body> <h3>Say "Hello" to: </h3> <s:form action="HelloWorld"> Name: <s:textfield name="name" /> <s:submit /> </s:form> </body> </html>
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Hello</title> </head> <body> <h3><s:property value="name"/></h3> </body> </html>