1

我使用旧的 struts 1x 框架开发 Web 应用程序。我创建了 2 个 Action formbeans。但我想知道我是否正确地完成了动作映射。因为当我调用 Action (PCLoginAction) [Relevant 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");

}
4

0 回答 0