struts.xml:
<struts>
<package name="struts2" namespace="/mystruts"
extends="struts-default">
<action name="sum" class="com.wjf.action.FirstAction">
<result name="positive">/positive.jsp</result>
<result name="negative">/negative.jsp</result>
</action>
</package>
<package name="demo" extends="struts-default" namespace="/">
<action name="submit" class="com.wjf.action.MoreSubmitAction">
<result name="save">/result.jsp</result>
<result name="print">/result.jsp</result>
</action>
</package>
</struts>
jsp页面:
<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>
action:
public class MoreSubmitAction extends ActionSupport implements ServletRequestAware{
private String msg;
private javax.servlet.http.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;
}
}
result.jsp
<body>
<h1>${result}</h1>
</body>
点击保存或者打印的时候报错:
No result defined for action com.wjf.action.MoreSubmitAction and result success
为什么?看不出来哪儿错了。。。
------解决方案--------------------
可是他在submit标签中有指定method方法,我觉得应该是struts没有配置动态方法调用,可以在struts.xml中加常量 配置下动态方法调用开启试下。
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>