<form name="addForm" method="post" action="./add.jsp">
...
</form>
<form name="editForm" method="post" action="./eidt.jsp">
...
</form>
<form name="delForm" method="post" action="./del.jsp">
...
</form>
...
</form>
<form name="editForm" method="post" action="./eidt.jsp">
...
</form>
<form name="delForm" method="post" action="./del.jsp">
...
</form>
如果action="add";则执行action中的doAdd()方法;
如果action="Update";则执行action中的doUpdate()方法;
如果action="Delete";则执行action中的doDelete()方法;
<form action="yourActionServletName" method=get>
...
</form>
在servlet中处理请求,并发送到相应的页面
1):action繼承DispatchAction.
2):struts-config.xml中加上method參數:
如:
<action name="custprodForm" type="com.universalec.wineasy.web.actions.CustprodAction" path="/custprod" parameter="method" scope="request">
<forward name="list" path="/jsp/cust/custprod_list.jsp"/>
<forward name="input" path="/jsp/cust/custprod_edit.jsp"/>
</action>
如果你的url為../cust.do?mehtod=add
則必須在action裡面有個對應的add()方法.
struts-config會自動跳入這方法,如果沒有,會報錯.
我的情况是现在有一个form,下面有增加、修改、删除三个按钮,底下是显示表的记录
如果点击增加则跳到增加页面
如果点击修改则跳到修改页面
如果点击删除则直接提交
问题一:怎么跳啊?
问题二:跳到页面之后,每个页面都有一个ActionForm吗?其实这几个页面都是包含同一个表中两个字段的修改
问题三:几个页面都能提交到同一Action吗?Action中怎么处理这几个不同页面(ActionForm只可以相同吗?怎么做)的不同要求呢--增加、修改、删除。
非常急,大家回答好了,肯定大大加分,谢谢了!~!!!!!!!!!!!!!!!!!!!!
jsp中调用servlet(用action或href)
servlet处理工作完成后用requestdispatcher转到一个jsp
handleMap.put("add", "addAction.jsp");
handleMap.put("delete", "delaction");
handleMap.put("search", "searchAction.jsp");
handleMap.put("edit", "editaction");
handleMap.put("list", "listaction");
StaffBean.getInstance().Connect();
} //Process the HTTP Get request
public void service(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
actionName = (String) request.getParameter("action");
if (actionName == null) {
actionName = "list";
}
/* if (actionName == null) {
RequestDispatcher rd = request.getRequestDispatcher("listaction");
rd.forward(request, response);
}
else {*/
String actionServlet = (String) handleMap.get(actionName);
RequestDispatcher rd = request.getRequestDispatcher(actionServlet);
rd.forward(request, response);
}这是控制器类的代码,很粗糙,仅供参考,欢迎指正
<html>
<head>
</head>
<body>
<form name="formName" method="post">
<input type="button" value="增加" onclick="add()">
<input type="button" value="删除" onclick="delete()">
<input type="button" value="修改" onclick="alter()"></form>
</body>
<script language="javascript">
function add(){
formName.action="add.jsp";
formName.submit();
}
function delete(){
formName.action="delete.jsp";
formName.submit();
}
function alter(){
formName.action="alter.jsp";
formName.submit();
}</script>
</html>
<a href="javascript:form_submit_a()"><img src="./edit.gif" width="82" height="30" border="0"></a>
<a href="javascript:form_submit_b()"><img src="./del.gif" width="82" height="30" border="0"></a>function form_submit_a()
{
document.form.action = "study_net_bbs_modify.jsp";
document.form.submit();
}
function form_submit_b()
{
document.form.action = "study_net_bbs_delete.jsp";
document.form.submit();
}
function form_submit_c()
{
document.form.action = "study_net_bbs_add.jsp";
document.form.submit();
}这样就可以了。