Struts +使用多个ActionForm

时间:2013-12-15 14:21:55

标签: java struts struts-1 actionform

我使用旧的struts 1x框架开发Web应用程序。我创建了2个Action formbeans。但我想知道我是否已正确完成了动作映射。当我调用Action时(PCLoginAction)[相关的actionformbean-- PCActionFormBean] 它没有重定向到相应的页面。以下是我的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>

以下显示了Action类中的execute方法。

@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 个答案:

没有答案