Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem regarding DispatchAction

 
mihir maniar
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
try replacing the


 
Vasudhaiv Naresh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
try replacing the

new ActionForward("success1");

with

mapping.findForward("success1");

Hope this works.
Regards,
Naresh
 
mihir maniar
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic