欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Struts DispatchAction,表單帶method參數選擇執行方法

DispatchAction是Struts包含的另一個(gè)能大量節省開(kāi)發(fā)時(shí)間的Action類(lèi)我想用DispatchAction來(lái)做一個(gè)從表單添加,修改,刪除記錄的功能
<html:form action="/MyDispatchAction">

MyDispatchAction中有add,alert,delete等方法,問(wèn)題是如何讓表單提交的時(shí)候加上參數呢?
比如:按下add button實(shí)現 MyDispathAction?method=add這樣的一次提交?


1.使用 DispatchAction
DispatchAction是Struts包含的另一個(gè)能大量節省開(kāi)發(fā)時(shí)間的Action類(lèi)。與其它Action類(lèi)僅提供單個(gè)execute()方法實(shí)現單個(gè)業(yè)務(wù)不同,DispatchAction允許你在單個(gè)Action類(lèi)中編寫(xiě)多個(gè)與業(yè)務(wù)相關(guān)的方法。這樣可以減少Action類(lèi)的數量,并且把相關(guān)的業(yè)務(wù)方法集合在一起使得維護起來(lái)更容易。

要使用DispatchAction的功能,需要自己創(chuàng )建一個(gè)類(lèi),通過(guò)繼承抽象的DispatchAction得到。對每個(gè)要提供的業(yè)務(wù)方法必須有特定的方法signature。例如,我們想要提供一個(gè)方法來(lái)實(shí)現對購物車(chē)添加商品清單,創(chuàng )建了一個(gè)類(lèi)ShoppingCartDispatchAction提供以下的方法:

那么,這個(gè)類(lèi)很可能還需要一個(gè)deleteItem()方法從客戶(hù)的購物車(chē)中刪除商品清單,還有clearCart()方法清除購物車(chē)等等。這時(shí)我們就可以把這些方法集合在單個(gè)Action類(lèi),不用為每個(gè)方法都提供一個(gè)Action類(lèi)。

在調用ShoppingCartDispatchAction里的某個(gè)方法時(shí),只需在URL中提供方法名作為參數值。就是說(shuō),調用addItem()方ǖ?URL看起來(lái)可能類(lèi)似于:

http://myhost/storefront/action/cart?method=addItem

其中method參數指定ShoppingCartDispatchAction中要調用的方法。參數的名稱(chēng)可以任意配置,這里使用的"method"只是一個(gè)例子。參數的名稱(chēng)可以在Struts配置文件中自行設定。


2.使用 LookupDispatchAction
org.apache.struts.actions.LookupDispatchAction類(lèi):

通常LookupDispatchAction主要應用于在一個(gè)表單中有多個(gè)提交按鈕,而這些按鈕又有一個(gè)共同的名字的場(chǎng)合,這些按鈕的名字和具體的ActionMapping的parameter屬性相對應。

配置LookupDispatchAction時(shí),應該在<action>元素中,把parameter屬性設置為"action",使它和<html:submit>標簽的property屬性相一致。

做一個(gè)隱藏變量就可以了
然后用JS判斷一下

<SCRIPT LANGUAGE="JavaScript">
<!--
function SetAction(opType) {
document.name1.action.value = opType
document.name1.submit();
}
//-->
</SCRIPT>
</head>
<body>

<html:form name="name1" action="/Del" type="XX.XX.Del">
<html:hidden property="action" />
<html:button property="update" value="UDDATE"
onclick="SetAction'updateDsp');"></html:button>
<html:button property="add" value="ADD"
onclick="SetAction'addDsp');"></html:button>
</html:form>
</body>
</HTML>


定義一個(gè)hidden的元素,JS控制提交的參數

用這個(gè)類(lèi)用多了就比較亂了,form的表單映射會(huì )煩死你。
同樣用樓上老兄的方法就可以,這個(gè)用在同個(gè)頁(yè)面上多個(gè)提交時(shí)候使用比較合適。

如果僅僅是一個(gè)頁(yè)面一個(gè)提交的話(huà),還有個(gè)更簡(jiǎn)單的方法。
<html:form action="/MyDispatchAction?action=add">

加個(gè)參數不就行了么~在action里面驗證這個(gè)參數,如果有form的話(huà)加個(gè)getset方法同樣驗證加個(gè)注釋也可以解決問(wèn)題。


An abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping. To configure the use of this action in your struts-config.xml file, create an entry like this:

<action path="/test"
type="org.example.MyAction"
name="MyForm"
scope="request"
input="/test.jsp"
parameter="method"/>
which will use the value of the request parameter named "method" to locate the corresponding key in ApplicationResources. For example, you might have the following ApplicationResources.properties:

button.add=Add Record
button.delete=Delete Record
And your JSP would have the following format for submit buttons:

<html:form action="/test">
<html:submit property="method">
<bean:message key="button.add"/>
</html:submit>
<html:submit property="method">
<bean:message key="button.delete"/>
</html:submit>
</html:form>
Your subclass must implement both getKeyMethodMap and the methods defined in the map. An example of such implementations are:

protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.add", "add");
map.put("button.delete", "delete");
return map;
}

public ActionForward add(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do add
return mapping.findForward("success");
}

public ActionForward delete(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do delete
return mapping.findForward("success");
}


Notes - If duplicate values exist for the keys returned by
getKeys, only the first one found will be returned. If no corresponding key
is found then an exception will be thrown. You can override the
method unspecified to provide a custom handler. If the submit
was cancelled (a html:cancel button was pressed), the custom
handler cancelled will be used instead.

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
struts中DispatchAction的使用
struts1中幾種常用的Action
CSDN技術(shù)中心 Struts心得—DispatchAction使用日記
FORM中使用onSubmit="return false"防止表單自動(dòng)提交,以及subm...
Html <form>表單標簽元素 </form>
覆蓋DispatchAction中的分發(fā)方法
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久