日期:2014-05-17 浏览次数:20689 次
<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>
<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>
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;
}
}
<body>
<h1>${result}</h1>
</body>