Struts1.2教程三 Struts1.2内置Action

1.ActionForward类



    在JSP项目中,我们经常需要进行一些JSP页面跳转,常用方法是<jsp:forward>跳转或者直接超链接,但是如果我们在Struts项目中使用这样的做法则在一定程度上违背了Struts框架,因为在Struts框架中要求每一个请求都通过中央控制器统一处理,以上两种方法则绕过了控制器直接进行网页间交互,在Struts框架中为统一符合Struts规范,提出了ActionForward类,客户端发送跳转请求通过控制器跳转,其配置方法为:

Java代码
<SPAN><SPAN><action path="/toIndex"</SPAN>   
             type="org.apache.struts.actions.ActionForwad" 
             paramter="/index.jsp" >  
</action></SPAN> 

<action path="/toIndex"
             type="org.apache.struts.actions.ActionForwad"
             paramter="/index.jsp" >
</action>

    2.IncludeAction类



      在JSP中一个JSP网页包含另一个网页一般采用动态包含和静态包含,这样的方式也绕开了Struts的控制器,为了把请求统一交由控制器来处理,Struts1.2提供了IncludeAction类,其使用方法如下:



Java代码
<action path="/include"   
             input="/index.jsp" 
             type="org.apache.struts.actions.IncludeAction" 
             paramter="/include.jsp" >  
</action> 

<action path="/include"
             input="/index.jsp"
             type="org.apache.struts.actions.IncludeAction"
             paramter="/include.jsp" >
</action>



     3.DispatchAction类

   

     在Struts1.2框架中我们每一个请求都对应了一个应用控制器,这样一旦我们的请求比较多就会产生许多的Action,为了减少控制器和便于我们提高开发效率,Struts1.2提供了一个DispatchAction类,我们可以通过这个类将一类业务统一由一个Action处理,比如:信息的添加、查询、删除等。其配置如下:


Java代码
<action path="/execute"   
             type="com.test.Dispatch.UserDispatchAction" 
             paramter="method" 
             ..... >  
</action> 

<action path="/execute"
             type="com.test.Dispatch.UserDispatchAction"
             paramter="method"
             ..... >
</action>   其应用控制器如下:

  

Java代码
public class UserDispatchAction extends DispatchAction {  
 
    //用户查询方法  
    public ActionForward userQuery(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {  
        // 调用用户查询业务方法  
        return super.execute(arg0, arg1, arg2, arg3);  
    }  
      
    //用户添加方法  
    public ActionForward userAdd(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {  
        // 调用用户添加业务方法  
        return super.execute(arg0, arg1, arg2, arg3);  
    }  
      
    //用户删除方法  
    public ActionForward userDel(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {  
        // 调用用户删除业务方法  
        return super.execute(arg0, arg1, arg2, arg3);  
    }  

你可能感兴趣的:(apache,jsp,框架,struts)