我目前是 Java EE 的新手,我刚刚完成了 Java EE 课程。我们被要求使用 MVC Struts 1 创建一个具有添加、编辑和删除功能的程序。
所以我的问题是,如何通过多个动作来做到这一点?您是否有任何教程解释了如何使用 Struts 创建成功的 Web 应用程序?
我目前是 Java EE 的新手,我刚刚完成了 Java EE 课程。我们被要求使用 MVC Struts 1 创建一个具有添加、编辑和删除功能的程序。
所以我的问题是,如何通过多个动作来做到这一点?您是否有任何教程解释了如何使用 Struts 创建成功的 Web 应用程序?
注册.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");}
}