分享
 
 
 

利用LookupDispatchAction实现一个form多个submit

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

[/url]

[url=http://struts.apache.org/api/overview-summary.html]Overview

Package

Class

Use

Tree

Deprecated

Index

Help

PREV CLASS NEXT CLASS

FRAMES NO FRAMES

All Classes

All Classes

SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

org.apache.struts.actions

Class LookupDispatchActionjava.lang.Object

org.apache.struts.action.Action

org.apache.struts.actions.DispatchAction

org.apache.struts.actions.LookupDispatchAction

public abstract class LookupDispatchAction

extends DispatchAction

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.

Field Summary

protected java.util.Map

keyMethodMap

Resource key to method name lookup.

protected java.util.Map

localeMap

Reverse lookup map from resource value to resource key.

Fields inherited from class org.apache.struts.actions.DispatchAction

clazz, log, messages, methods, types

Fields inherited from class org.apache.struts.action.Action

defaultLocale, servlet

Constructor Summary

LookupDispatchAction()

Method Summary

ActionForward

execute(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it).

protected abstract java.util.Map

getKeyMethodMap()

Provides the mapping from resource key to method name.

protected java.lang.String

getLookupMapName(javax.servlet.http.HttpServletRequest request, java.lang.String keyName, ActionMapping mapping)

Lookup the method name corresponding to the client request's locale.

protected java.lang.String

getMethodName(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String parameter)

Returns the method name, given a parameter's value.

private java.util.Map

initLookupMap(javax.servlet.http.HttpServletRequest request, java.util.Locale userLocale)

This is the first time this Locale is used so build the reverse lookup Map.

Methods inherited from class org.apache.struts.actions.DispatchAction

cancelled, dispatchMethod, getMethod, unspecified

Methods inherited from class org.apache.struts.action.Action

addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

localeMap

protected java.util.Map localeMap

Reverse lookup map from resource value to resource key.

keyMethodMap

protected java.util.Map keyMethodMap

Resource key to method name lookup.

Constructor Detail

LookupDispatchAction

public LookupDispatchAction()

Method Detail

execute

public ActionForward execute(ActionMapping mapping,

ActionForm form,

javax.servlet.http.HttpServletRequest request,

javax.servlet.http.HttpServletResponse response)

throws java.lang.Exception

Process the specified HTTP request, and create the corresponding HTTP

response (or forward to another web component that will create it).

Return an ActionForward instance describing where and how

control should be forwarded, or null if the response has

already been completed.

Overrides:execute in class DispatchAction

Parameters:mapping - The ActionMapping used to select this instancerequest - The HTTP request we are processingresponse - The HTTP response we are creatingform - The optional ActionForm bean for this request (if any)

Returns:Describes where and how control should be forwarded.

Throws:

java.lang.Exception - if an error occurs

initLookupMap

private java.util.Map initLookupMap(javax.servlet.http.HttpServletRequest request,

java.util.Locale userLocale)

This is the first time this Locale is used so build the reverse lookup Map.

Search for message keys in all configured MessageResources for

the current module.

getKeyMethodMap

protected abstract java.util.Map getKeyMethodMap()

Provides the mapping from resource key to method name.

Returns:Resource key / method name map.

getLookupMapName

protected java.lang.String getLookupMapName(javax.servlet.http.HttpServletRequest request,

java.lang.String keyName,

ActionMapping mapping)

throws javax.servlet.ServletException

Lookup the method name corresponding to the client request's locale.

Parameters:request - The HTTP request we are processingkeyName - The parameter name to use as the properties keymapping - The ActionMapping used to select this instance

Returns:The method's localized name.

Throws:

javax.servlet.ServletException - if keyName cannot be resolvedSince:

Struts 1.2.0

getMethodName

protected java.lang.String getMethodName(ActionMapping mapping,

ActionForm form,

javax.servlet.http.HttpServletRequest request,

javax.servlet.http.HttpServletResponse response,

java.lang.String parameter)

throws java.lang.Exception

Returns the method name, given a parameter's value.

Overrides:getMethodName in class DispatchAction

Parameters:mapping - The ActionMapping used to select this instanceform - The optional ActionForm bean for this request (if any)request - The HTTP request we are processingresponse - The HTTP response we are creatingparameter - The ActionMapping parameter's name

Returns:The method's name.

Throws:

java.lang.ExceptionSince:

Struts 1.2.0

[/url]

[url=http://struts.apache.org/api/overview-summary.html]Overview

Package

Class

Use

Tree

Deprecated

Index

Help

PREV CLASS NEXT CLASS

FRAMES NO FRAMES All Classes

All Classes

SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2004 - The Apache Software Foundation

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有