diffrence between dispatch action and lookupdispatch action

write simple web appliction (insert records in database)

Answers were Sorted based on User's Feedback



diffrence between dispatch action and lookupdispatch action write simple web appliction (insert r..

Answer / mastan reddy

LookupDispatchAction class is much like the DispatchAction
class except that, it uses a Java Map and
ApplicationResource.properties file to dispatch methods. At
run time, this class manages to delegate the request to one
of the methods of the derived Action class. Selection of a
method depends on the value of the parameter passed from
the incoming request. LookupDispatchAction uses this
parameter value to reverse-map to a property in the Struts
Resource bundle file (ie..ApplicationResource.properties).
this eliminates the need of creating an instance of
ActionForm class.

Is This Answer Correct ?    47 Yes 7 No

diffrence between dispatch action and lookupdispatch action write simple web appliction (insert r..

Answer / raj

Here i would like to add few points to Mastan answer.
LookupDispatchAction is only takes place when u want
Internationalization (i18n) in ur application.

Otherwise DispatchAction is enough.

Is This Answer Correct ?    19 Yes 1 No

diffrence between dispatch action and lookupdispatch action write simple web appliction (insert r..

Answer / k.v.s.ravindrareddy

In the DispatchAction there are two jsp's with different
actions so we need to write two action classes and both
action classes should do different job for any class.
(insertStudent or updateStudent) instead of writing two
classes write one Action class with different methods and it
contains the diffenet logic. and in struts-config.xml file
parameter attribute should be parameter.....

In the LookupDispatchAction also like DispatchAction
here also instead of writing two Action class write two
methods in one class... and write getKeyMethodMap()
object.... This LookupDispatchAction is I18N and
DispatchAction....

Is This Answer Correct ?    9 Yes 3 No

diffrence between dispatch action and lookupdispatch action write simple web appliction (insert r..

Answer / mahi

LookupDispatch Action is useful when we are using
Internalisation functionality.....
otherwise we can use Diaspatch Action....


Thanks

Is This Answer Correct ?    4 Yes 1 No

diffrence between dispatch action and lookupdispatch action write simple web appliction (insert r..

Answer / chandu

The main constraint in the DispatchAction is the method name
in the action class and the button name in the jsp page
should be the same. But here in LookupDispatchAction, we can
have different names for the buttons and the methods.
Here i would like to add few points to Mastan answer.
LookupDispatchAction is only takes place when u want
Internationalization (i18n) in ur application.

Otherwise DispatchAction is enough

Is This Answer Correct ?    4 Yes 3 No

diffrence between dispatch action and lookupdispatch action write simple web appliction (insert r..

Answer / java_developer

The difference between LookupDispatchAction and
DispatchAction is that the actual method that gets called in
LookupDispatchAction is based on a lookup of a key value
instead of specifying the method name directly.

Details :

LookupDispatchAction is subclass of DispatchAction.
In case of DispatchAction, you have to declare the method
name in the JSP page.
For Example :
http://localhost:8080/emp/empaction.do?step=add // IN CASE
OF DispatchAction
here step=add , we are delaring method name in JSP.
or
<html:submit property="step">Add</html:submit> //IN CASE OF
DispatchAction
so we can't use localization for button.


To over come both the issues below
a)method name declaration in JSP
b)can't use localization for button
We will go for LookupDispatchAction.

In the LookupDispatchAction :
For example :
If there are three operation like add, delete, update employee.
You can create three different Actions ?
AddEmpAction, DeleteEmpAction and UpdateEmpAction.
This is a valid approach, although not elegant since there
might be duplication of code across
the Actions since they are related. LookupDispatchAction is
the answer to this
problem. With LookupDispatchAction, you can combine all
three Actions into one.

Example :
Step 1.
three buttons might be
<html:submit property="step">
<bean:message key="button.add"/>
</html:submit>
<html:submit property="step">
<bean:message key="button.delete"/>
</html:submit>
<html:submit property="step">
<bean:message key="button.update"/>
</html:submit>

//No need method name declaration in JSP . Button name from
resource bundle.

Step 2.
In the the Resource Bundle. //Here you can add localization.
button.add=Add
button.delete=Delete
button.update=Update

Step 3.
Implement a method named getKeyMethodMap() in the subclass
of the
LookupDispatchAction. The method returns a java.util.Map. The
keys used in the Map should be also used as keys in Message
Resource
Bundle.

public class EmpAction extends LookupDispatchAction {

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


public ActionForward add(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
//your logic
mapping.findForward("add-success");
}

public ActionForward delete(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
//your logic
mapping.findForward("delete-success");
}

public ActionForward update(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
//your logic
mapping.findForward("update-success");
}

}

in struts-config.xml

<action path="/empaction"
input="/empform.jsp"
type="list.EmpAction"
parameter="step"
scope="request"
validate="false">
<forward name="add-success"
path="addEmpSuccess.jsp"
redirect="true"/>
<forward name="delete-success"
path="deleteEmpSuccess.jsp"
redirect="true"/>
<forward name="update-success"
path="updateEmpSuccess.jsp"
redirect="true"/>
</action>

for every form submission, LookupDispatchAction does the
reverse lookup on the resource bundle to get the key and
then gets the method
whose name is associated with the key from
getKeyMethodmap().


Flow of LookupDispatchAction:
a) Form the button name "Add" get the key "button.add" fro
resource bundle.
b) then in the Map getKeyMethodMap() find the value
associated with the key "button.add".
c) value from the Map is "add" . then call add() method of
the same action class.

Is This Answer Correct ?    0 Yes 0 No

diffrence between dispatch action and lookupdispatch action write simple web appliction (insert r..

Answer / sekhar babu

LookupDispatchAction is used for I18N where as
DispatchAction is not useful for I18N

Is This Answer Correct ?    14 Yes 15 No

diffrence between dispatch action and lookupdispatch action write simple web appliction (insert r..

Answer / ala

Both LookupDispatchAction and DispatchAction are subclass
of ActionClass.The Advantage of LookupDispatchAction is the
methodName should be different.

Is This Answer Correct ?    5 Yes 31 No

Post New Answer

More Struts Interview Questions

How can I make own ActionServlet? with example

8 Answers   IBM, TCS,


how handle when client send multiple request at atime for single servlet

5 Answers   Aditya Birla, IBM,


What is Model 1 and Model 2?

3 Answers  


Why we use struts over servlets?

0 Answers  


what is the difference between SAX Parser and DOM Parser??

14 Answers   Cap Gemini, Goldman Sachs, HCL, Hidden Brains, HP,






Can we have more than one struts-config.xml file for a single struts application?

0 Answers  


What are the core classes of the struts framework?

0 Answers  


Provide some important Struts2 constants that you have used?

0 Answers  


How to pass runtime Parameter in Struts1.2?

2 Answers  


What is the default location of result pages and how can we change it?

0 Answers  


In ActionClass we can use only one action i.e execute(), but in DispatchAction we can use multiple actions.My question is , we can use multiple actions in Action class if(action.equals("add") if(action.equals("update"). Then when to use Action and DispatchAction which is frequently in webapplications.

2 Answers  


Explain the components of struts?

0 Answers  


Categories