您的位置:首页 > 编程语言 > Java开发

Struts-config.xml配置文件讲解(三)

2007-07-30 20:37 513 查看
四、 配置FormBean
<form-bean / >用来定义将要绑定到Action的FormBean的实例。语法如下:
<form-beans>
<form-bean name="name used to uniquely identify a FormBean"
type=”fully qualified class name of FormBean"/>
</form-beans>
例:
<form-beans>
<form-bean name="lookupForm" type="wiley.LookupForm" />
</form-beans>

五、 配置全局转发
全局转发可以定义几个<forward/>子元素,struts首先会在<action-mappings>元素中找对应的<forward>,若找不到,则到全局转发配置中找。语法如下:
<global-forwards>
<forward name="unique target identifier"
path="context-relative path to targetted resource "/>
</global-forwards>
除了name及path属性之外,还有一个redirect属性,如果redirect设为true的时候,则用HttpServletResponse.sendRedirect()方法,否则用RequestDispatcher.forward()方法,缺省为false。
注:如果为true,则用HttpServletResponse.sendRedirect()方法,此时存储在原来的HttpServletRequest中的值将会丢失。
例子:
<global-forwards>
<forward name="success" path="/welcome.jsp"/>
<forward name="failure" path="/index.jsp"/>
</global-forwards>
六、 配置<action-mappings>
它可以定义几个<action / >子元素,它主要是定义Action实例到ActionServlet类中,语法如下:
<action-mappings>
<action path="context-relative path mapping action to a request"
type="fully qualified class name of the Action class"
name="the name of the form bean bound to this Action">
<forward name="forwardname1" path="context-relative
<forward name="forwardname2" path="context-relative path"/>
</action>
</action-mappings>
<action/>属性及其描述信息如下:
属 性 描 述 信 息
Path 在浏览器的URL中输入的字符(必须的)
Type 连结到本映射的Action的全称(可选的)
Name 与本操作关联的Action Bean在<form-bean/>中定义name名(可选的)
Scope 指定ActionForm Bean的作用域(session和request),缺省为session。(可选的)
Input 当Bean发生错误时返回的控制。(可选的)
ClassName 指定一个调用这个Action类的ActionMapping类的全名。缺省用org.apache.struts.action.ActionMapping,(可选的)
Forward 指定处理相应请求所对应的JSP页面。(可选的)
Include 如果没有forward的时候,它起forward的作用。(可选的)
Validate 若为true,则会调用ActionForm的validate()方法,否则不调用,缺省为true。(可选的)
例子:
<action-mappings>
<action path="/lookupAction"
type="wiley.LookupAction"
name="LookupForm"
scope="request"
validate="true"
input="/index.jsp">
<forward name="success" path="/quote.jsp"/>
<forward name="faliue" path="/index.jsp"/>
</action>
</action-mappings>v
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: