This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes Problem regarding DispatchAction Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "Problem regarding DispatchAction" Watch "Problem regarding DispatchAction" New topic
Author

Problem regarding DispatchAction

mihir maniar
Ranch Hand

Joined: Sep 09, 2003
Posts: 88
i have a class UserAction which extends DispatchAction Class.This class has 2 methods "Add" and "Modify" to perform different actions on the database and i then implement them.i make the necessary changes in the struts-config.xml.
<action-mappings> <action path="/User" type="com.actions.login.UserAction" parameter="process" />
</action-mappings>

Now i want to implement some links on a jsp page with the parameter that decides which method is to be called inside this DispatchAction class of mine. So my question is how do i write the parameter "process" in the following scenario while creating the link on the jsp page.
<html:link action="User">Modify</html:link>
<html:link action="User">Add</html:link>

i hope i am descriptive enough to make situation clear.THx in advance,
Vasudhaiv Naresh
Ranch Hand

Joined: May 13, 2005
Posts: 57
Hi Mihir,

In your case, I hope the following would solve the problem :

<html:link action="User.do?process=modify">Modify</html:link>
<html:link action="User.do?process=add">Add</html:link>

Regards,
Naresh
mihir maniar
Ranch Hand

Joined: Sep 09, 2003
Posts: 88
when i implement this solution it still gives me the error "page cannot be found" but the websphere does not give any error.Is there any elementary mistake that i am doing? Please help. Thank you.
Vasudhaiv Naresh
Ranch Hand

Joined: May 13, 2005
Posts: 57
Hi again!
In the segment of the struts-config.xml, that you've attached I fing that there's no entry for even a single forward.
What does your com.actions.login.UserAction class's execute method return? Since there's no forward sub element in the "action" tag, there must be a global forward which is returned from the "UserAction" class. If its not the case, then I hope something is missing.
Can you paste the action class's execute method body? And also the corresponding "action-mapping" ?

Thanks & Regards,
Naresh
mihir maniar
Ranch Hand

Joined: Sep 09, 2003
Posts: 88
this is my struts-config file.

<action path="/User"
type="com.actions.login.UserAction"
parameter="process">
<forward name="success1" path="/jsp/success1.jsp"></forward>
<forward name="success2" path="/jsp/success2.jsp"></forward>
<forward name="success3" path="/jsp/success3.jsp"></forward>
</action>


this is my action class i.e. useraction.java

/*
* Created on Nov 4, 2005
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.actions.login;

/**
* @author mmaniar1
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class UserAction extends DispatchAction
{
public ActionForward add(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{

return new ActionForward("success1");
}

public ActionForward update(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{

return new ActionForward("success2");
}

public ActionForward remove(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{


return new ActionForward("success3");
}
}
Vasudhaiv Naresh
Ranch Hand

Joined: May 13, 2005
Posts: 57
Hi!
try replacing the


Vasudhaiv Naresh
Ranch Hand

Joined: May 13, 2005
Posts: 57
Hi!
try replacing the

new ActionForward("success1");

with

mapping.findForward("success1");

Hope this works.
Regards,
Naresh
mihir maniar
Ranch Hand

Joined: Sep 09, 2003
Posts: 88
if i call the link http://.../User.do?process=modify then it works but the way u suggested me earlier i.e. to put it in the html:link tag still doesn't work. ne other ideas. and yes could you plz ealborate what is the difference between the "mapping.findforward" and "new ActionForward" ways which made the difference in my case. Thx in advance.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Problem regarding DispatchAction
 
Similar Threads
Error: DispatchMapping[/login] does not define a handler property
Passing every control to the ActionServlet
can i call DispatchAction from global forward
DispatchAction in struts 1.1
DispatchAction:seems fine, but doesn't work