includeAction与ForwardAction

ForwardAction

   基于struts的WEB应用系统通常情况下应该避免JSP页面之间的跳转.因为这样跳转的用户请求没有
经过Struts的处理,会导致很多在Struts框架中进行的处理不起的作用.
   对于每个用户的请求,struts的RequestProcessor将会进行一系列的处理,其中包括了国际化,权限
缓存等多方面.如果采用页面之间的直接跳转会导致很多内容都需要自己处理.

在struts中配置ForwardAction
   <action path="home"
       type="org.apache.struts.actions.ForwardAction"
       parameter="/index.jsp"
   />
   其中path属性是Action的匹配路径,type属性说明实现Action的类,parameter属性用于指定往哪转发
也就是转发的目的URI.这三个属性是必须的,其它的可以省略.
forward属性和ForwardAction
   使用forward进行页面跳转的配置方法如下
   <action path="/home"
       forward="/index.jsp"
   />
   forward属性和ForardAction在页面中使用时是没有区别的,并且在通常情况下struts对这两种形式
的跳转的处理也是相同的.但是使用自己的RequestProcessor并且覆盖了父类的processForwardConfig()
方法时,这两种方式就存在一定的区别了.

IncludeAction

   IncludeAction类的意义类似于ActionForward类,它和页面中的<jsp:include>动作或Servlet中的
RequestDispatcher的include()方法执行的功能一样的.在基于struts框架结构的应用中,最好不要在
<jsp:include>标记中直接引用另一个JSP页面,而是通过IncludeAciton来实现页面之间的引用,这样比较
安全等等.
   IncludeAction的使用
IncludeAction的使用和Forward基本相同,在页面中还可以通过<jsp:include>标记来调用.
<jsp:include page="/somePath/someAction.do" />
   IncludeAction的配置
   <action path="/include"
       type="org.apache.struts.actions.IncludeAction"
       parameter="/include.jsp"
   />
   include属性和IncludeAction
   Struts也可以通过使用include属性来在Action的配置文件中直接定义被引用的页面.如
   <action path="/include"
       include="/include.jsp"
   />

posted on 2009-12-31 18:52  天行者2009  阅读(924)  评论(0编辑  收藏  举报