Struts + Using Multiple ActionForms

1k Views Asked by At

Im using old struts 1x framework to develop a web application.I have created 2 Action formbeans.But I want to know whether I have done the action mapping correctly. Beacuse when I call the Action (PCLoginAction) [Relevant actionformbean-- PCActionFormBean] it doesn't redirect to corresponding pages.Following is my struts-congif.xml

<struts-config>
    <form-beans>
        <form-bean name="LoginActionFormBean" 
                   type="com.myapp.struts.LoginActionFormBean"/>
        <form-bean name="PCActionFormBean" 
                   type="com.model.computer.PCActionFormBean"/>
    </form-beans>

    <action-mappings>
        <action input="/" name="LoginActionFormBean" path="/login" scope="request" type="com.myapp.struts.LoginAction">
            <forward name="success" path="/success.jsp"/>
            <forward name="failure" path="/failure.jsp"/>
            <forward name="home" path="/home.jsp"/>
        </action>

        <action  input="/" name="PCActionFormBean"  path="/desktopPath" scope="request" type="com.myapp.struts.PCLoginAction" >
                <forward name="desktops" path="/desktops.jsp"/>
                <forward name="failure" path="/failure.jsp"/>
        </action>
    </action-mappings>

    <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
    <message-resources parameter="com/myapp/struts/ApplicationResource"/>    
</struts-config>

Following shows the execute method in Action class.

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

    PCActionFormBean actiobean = (PCActionFormBean) form;

    Computer c1 =new Computer();
    Computer c2 =new Computer();

    c1.setName("Accer");
    c2.setName("HP");

    List<Computer> list= new ArrayList<Computer>();

    list.add(c2);
    list.add(c1);

    actiobean.setList(list);

    return mapping.findForward("desktops");

}
0

There are 0 best solutions below