aspose file tools *
The moose likes Struts and the fly likes Difference Between LookupDispatch Action & DispatchAction? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Difference Between LookupDispatch Action & DispatchAction?" Watch "Difference Between LookupDispatch Action & DispatchAction?" New topic
Author

Difference Between LookupDispatch Action & DispatchAction?

Ashok A Kumar
Greenhorn

Joined: Jul 01, 2010
Posts: 19
Hi,
What is the actual difference between LookupDispatchAction and DispatchAction? I've tried reading some points over the web and its not clear.. "LookupDispatchAction Shields the application from the side effect of I18N" , Also it refers about ResourceBundle and Locale Independent.. Do i need to understand ResourceBundle and Locale before diving into Struts???.. Also i don't have much idea about I18N..

Please advise...

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No, you don't need to understand I18N to get started with Struts (although some knowledge of resource bundles would be useful).

However, it looks like you're asking about Struts 1, which I'd try to avoid unless you have an actual reason for using it. Aim for Struts 2 if you're interested in Struts.

The basic difference is that LookupDispatchAction uses a map and the message key to look up (hence the Lookup part of the class name) which method to run, while DispatchAction uses the parameter value directly. See their corresponding Javadocs to read more:

http://struts.apache.org/1.x/struts-extras/apidocs/org/apache/struts/actions/DispatchAction.html
http://struts.apache.org/1.x/struts-extras/apidocs/org/apache/struts/actions/LookupDispatchAction.html
Ashok A Kumar
Greenhorn

Joined: Jul 01, 2010
Posts: 19
Hi David,
Thanks for the links and i've understood the difference between these two, However I've started learning struts long back and i've felt the learning curve is kind of steep, Parallely i've started updating myself in JSF and understood it has very distinct and significant advantage over Struts.. These are all the points that i've come across

• Eliminated the need for a Form Bean
• Eliminated the need for a DTO Class
• Allows the use of the same POJO on all Tiers because of the Backing Bean

Kindly advise me on the above, Your valuable suggestion will defantely help in moving forward and it will shape my learing path.

Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

JSF is substantially more complex than Struts.

You're also talking about Struts 1, which is *quite* old both in time and in approach; frameworks like Struts 2, Spring MVC, Stripes, etc. also eliminate Struts 1 issues.
patil biradar
Greenhorn

Joined: Oct 22, 2012
Posts: 1
i am getting error please enebody please help me
this is example om lookupdispatch action


page0.jsp
---------------------------------
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<html:form action="registrationform0">
<bean:message key="regform0.firstname"/>
<html:text property="firstname"/><br>
<bean:message key="regform0.lastname"/>
<html:text property="lastname"/><br>
<html:submit property="decider">
</html:submit>

</html:form>


page1.jsp
---------------------------------
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<html:form action="registrationform1">
<bean:message key="regform1.age"/>
<html:text property="age"/><br>
<bean:message key="regform1.email"/>
<html:text property="email"/><br>
<html:submit property="decider">
<bean:message key="regform1.submit"/>
</html:submit>

</html:form>

page2.jsp
------------------------------------
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<html:form action="registrationform2">
<bean:message key="regform2.mobileNo"/>
<html:text property="mobileNo"/><br>
<bean:message key="regform2.adress"/>
<html:text property="adress"/><br>
<html:submit property="decider">
<bean:message key="regform2.submit"/>
</html:submit>

</html:form>


success.jsp
---------------------------------------
success


RegistrationAction.java
-------------------------------------------------
package com.example;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.actions.LookupDispatchAction;

public class RegistrationAction extends LookupDispatchAction
{

private static Log log =
LogFactory.getLog(RegistrationAction.class);
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected Map getKeyMethodMap()
{

HashMap map=new HashMap();
map.put("regform0.submit"," step0");
map.put("regform1.submit"," step1");
map.put("regform2.submit"," step3");
return map;
}

public ActionForward step0(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//RegistrationForm r1=(RegistrationForm)form;

return mapping.findForward("success");
}

public ActionForward step1(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//RegistrationForm r1=(RegistrationForm)form;

return mapping.findForward("success");
}

public ActionForward step2(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
RegistrationForm r1=(RegistrationForm)form;

System.out.println(r1.getFirstname());
System.out.println(r1.getLastname());
System.out.println(r1.getAge());
System.out.println(r1.getMobileNo());
System.out.println(r1.getAdress());
System.out.println(r1.getEmail());


return mapping.findForward("success");
}


}




RegistrationForm.java
---------------------------------------------
package com.example;

import org.apache.struts.action.ActionForm;

public class RegistrationForm extends ActionForm
{
private String firstname;
private String lastname;
private int age;
private String email;
private int mobileNo;
private String adress;

private String decider="step0";


public String getDecider() {
return decider;
}
public void setDecider(String decider) {
this.decider = decider;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getMobileNo() {
return mobileNo;
}
public void setMobileNo(int mobileNo) {
this.mobileNo = mobileNo;
}
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}

}


application.properties
------------------------------------
regform0.firstname=FirstName
regform0.lastname=LastName
regform0.submit=Next
regform1.age=Age
regform1.email=Email
regform1.submit=Next
regform2.mobileNo=MobileNo
regform2.adress=Adress
regform2.submit=Finish





struts.config.xml
----------------------------------
<form-bean
name="registration"

type="com.example.RegistrationForm"/>


<action
path="/registrationform0"
type="com.example.RegistrationAction"
name="registration"
parameter="decider">

<forward name="success" path="/jsp/Success.jsp" redirect="true"/>

</action>


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference Between LookupDispatch Action & DispatchAction?