我目前刚接触Java EE,刚刚在Java EE中完成了我的课程。我们被要求使用MVC Struts 1创建一个添加,编辑和删除的程序。
所以我的问题是,如何通过多个动作做到这一点?您是否有任何教程解释如何使用Struts创建成功的Web应用程序?
答案 0 :(得分:0)
<强> BEST LINK TO LEARN 强>
register.jsp
<form name="myform">
// other inputs going here
<input type="button" name="add" value="add" id="add" onclick="submitAction(this)">
<input type="button" name="update" value="update" id="update" onclick="submitAction(this)">
<input type="button" name="delete" value="delete" id="delete" onclick="submitAction(this)">
</form>
的javascript:
function submitAction(actType)
{
document.myform.action = actType.id;
document.myform.submit();
}
<action name="MyUpdateAction" type="test.MyUpdateAction" path="/update" input="/register.jsp">
<forward name="success" path="/updated.jsp" />
<forward name="failure" path="/failure.jsp" />
</action>
<action name="MyAddAction" tepe="test.MyAddAction" path="/add" input="/register.jsp">
<forward name="success" path="/added.jsp" />
<forward name="failure" path="/failure.jsp" />
</action>
<action name="MyDeleteAction" type="test.MyDeleteAction" path="/delete" input="/register.jsp">
<forward name="success" path="/deleted.jsp" />
<forward name="failure" path="/failure.jsp" />
</action>
包测试中的Struts操作:
public class MyUpdateAction extends org.apache.struts.action.Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{ //do update Stuff...
if () {
return mapping.findForward("success");
} else {
return mapping.findForward("failure");}
}
public class MyAddAction extends org.apache.struts.action.Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{ //do add Stuff...
if () {
return mapping.findForward("success");
} else {
return mapping.findForward("failure");}
}
public class MyDeleteAction extends org.apache.struts.action.Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{ //do delete Stuff...
if () {
return mapping.findForward("success");
} else {
return mapping.findForward("failure");}
}