最近学Struts框架,其原理没有搞懂,那位帮助解释下
例子:
 
struts.xml片断
...
<package name="struts2" namespace="/mystruts" extends="struts-default">
<action name="sum" class="action.FirstAction">
<result name="positive">/positive.jsp</result>
<result name="negative">/negative.jsp</result>
</action>
</package>
...
----------------------------------------------------------------------------
FirstAction.java
 
package action;import com.opensymphony.xwork2.ActionSupport;public class FirstAction extends ActionSupport { /**
 * 
 */
private static final long serialVersionUID = 1L;


private int operand1;
private int operand2;

public int getOperand1() {
return operand1;
}
public void setOperand1(int operand1) {
this.operand1 = operand1;
}
public int getOperand2() {
return operand2;
}
public void setOperand2(int operand2) {
this.operand2 = operand2;
}

public String execute() throws Exception
{
if(getSum() >=0){
return "positive";
}
else
{
return "negative";
}
}
public int getSum() {
// TODO Auto-generated method stub
return operand1 + operand2;
}

}
------------------------------------------------------------------
sum.jsp
<%@ page language="java"  pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head><title>输入操作数</title>
</head>
<body>
求代数和
<br/>
<s:form action="mystruts/sum.action">
<s:textfield name="operand1" label="操作数1" />
<s:textfield name="operand2" label="操作数2" />
<s:submit value="代数和"/>
</s:form>
</body>
</html>
------------------------------------------------------------------
negative.jsp<%@ page language="java"  pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head><title>显示代数和</title>
</head>
<body>
代数和为负整数
<h1><s:property value="sum"/> </h1>
</body>
</html>
----------------------------------------------------------------------
positive.jsp
<%@ page language="java"  pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>显示代数和</title>
</head>
<body>
代数和为非负整数
<h1><s:property value ="sum" /> </h1>
</body>
</html>我想知道的是,最后页面上显示的结果的数是怎么得到地,即数据流向,即<s:property value ="sum" />表示什么意思,与<action name="sum" class="action.FirstAction">又是什么关系?因为还有一个例子如下:struts.xml片断:
.........
<package name="demo"  extends="struts-default">
<action name="submit" class="action.MoreSubmitAction">
<result name="save">/result.jsp</result>
<result name="print">/result.jsp</result>
</action>
</package>
....
-----------------------------------------------MoreSubmitAction.java
 
package action;import javax.servlet.http.HttpServletRequest;import com.opensymphony.xwork2.ActionSupport;public class MoreSubmitAction extends ActionSupport {
/**
 * 
 */
private static final long serialVersionUID = 1L;

private String msg;
private HttpServletRequest request;

public void setServletRequest(HttpServletRequest request) {
this.request = request;
}

public String save() throws Exception
{
request.setAttribute("result", "成功保存["+msg+"]");
return "save";
}

public String print() throws Exception
{
request.setAttribute("result", "成功打印["+msg+"]");
return "print";
}

public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}

}-----------------------------------------------
more_submit.jsp<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head><title>My JSP 'hello.jsp' starting page</title>
</head>
<body><s:form action ="submit.action">
<s:textfield name="msg" label="输入内容"/>
<s:submit name="save" value="保存" align="left" method="save" />
<s:submit name="print" value="打印" align="left" method="print"/>
</s:form></body>
</html>
---------------------------------------------------
result.jsp<%@ page language="java"  pageEncoding="GBK"%><html>
<head><title>提交结果</title>
</head>
<body>
<h1>${result}</h1>
</body>
</html>--------------------------------------
此时运行时,点按钮报错如下:
HTTP Status 404 - There is no Action mapped for namespace / and action name submit.--------------------------------------------------------------------------------type Status reportmessage There is no Action mapped for namespace / and action name submit.description The requested resource (There is no Action mapped for namespace / and action name submit.) is not available.
--------------------------------------------------------------------------------Apache Tomcat/7.0.27那位高手帮助指定下.目前看了很多有关SSH的书,总觉得结果得来莫名其妙地,小弟在此跪求赐教!!!