- Java code
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; }}
这是HelloWorld.java的内容
- XML code
<!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>
这是struts.xml的内容
- JScript code
<%@ 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>
这是SayHello.jsp的内容,不知道选用的论坛代码格式对不对。。
- JScript code
<%@ 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>
这是HelloWorld.jsp的内容
对应路径:
struts.xml是*/src/struts.xml
HelloWorld.java是*/src/tutorial/HelloWorld.java
SayHello.jsp和HelloWorld.jsp都是在*/WebContent下
PS:SayHello.jsp打开无问题
麻烦大家给个修改方法 多谢
------解决方案--------------------
<action name="HelloWorld" class="tutorial.HelloWorld" method="excute">
<result name="success">HelloWorld.jsp</result>
</action>
------解决方案--------------------
<s:form action="/工程名/HelloWorld.action">
Name: <s:textfield name="name" />
<s:submit />
</s:form>
------解决方案--------------------
action="tutorial/HelloWird"这样试试
------解决方案--------------------
<s:form action="tutorial/HelloWorld">
这样改下。
------解决方案--------------------
http://zuoqiang.iteye.com/blog/670569
------解决方案--------------------