1

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");

}
Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
Amila Iddamalgoda
  • 4,166
  • 11
  • 46
  • 85
  • 1
    Try to create a form in JSP page and set the values by submitting the form and in input tag give the path of that JSP page. – Maninder Dec 15 '13 at 15:32

0 Answers0