struts 1.x 学习笔记 持续更新

xiaoxiao2026-03-19  6

最后更新:2009-7-6 

1.可以通过在web.xml这配置,统一管理项目中的error显示页面。强…… 

<error-page> <error-code>404</error-code> <location>/commom/404.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/commom/500.jsp</location> </error-page>

 

     如果需要对特定类型的error做显示,还可以设定 <exception-type>来达到效果  <error-page> <exception-type>javax.servlet.ServletException</exception-type> <location>/commom/system_error.jsp</location> </error-page> <error-page> <exception-type>java.io.IOException</exception-type> <location>/commom/system_ioerror.jsp</location> </error-page>   2.<nested:xx>标签(转载)

自己注:这样就可以使用bean的嵌套,达到见到bean代码的目的。

Struts Nested 标签库的一部分标签用于表达JavaBean 的嵌套系,有一部分标签在特定的级别提供和其他Struts标签库标签相同的功能。

<nested:nest>,定义一个新的嵌套级别 <nested:writeNesting>,输出当前嵌套级别信息

 

定义两个<nested:nest>标签,第一个<nested:nest>标签嵌套在<html:form>标签中,如下:

 

<nested:nest property = "person"> Last name :<nested:text property="lastName"/> </nested:nest>

 

 

以上<nested:nest>标签的上层JavaBean为於<html:form>表单标签对应的PersonForm Bean,<nested:nest>标签的property属性为“person",代表PersonForm Bean的person属性,这个person属性代表Person Bean,因此嵌套在<nested:nest>标签内部的Nested标签都相对于这个Person Bean,例如第一个<nested:text>标签的property属性”lastName“,代表Person Bean的lastName属性。

 

第二个<nested:nest>标签嵌套在第一个<nested:nest>标签内部:如下

<html:form action="/showPerson"> <nested:nest property="person"> ............. <nested:nest property="address"> Current nesting is :<nested:writeNesting/><br> Street 1:<nested:text property="street1"/><BR> ..... </nested:nest> </nested:nest> </html:form>

  

在以上代码中,第二个<nested:nest>标签的property属性为“address",代表PersonBean 的address属性,这个address属性代表Address Bean,因此嵌套在第二个<nested:nest>标签内部的Nested标签都相对於这个Address Bean。

 

   第二个<nested:nest>标签内还嵌套了一个<nested:writeNesting>标签,它显示当前的嵌套级别,输出结果为”person.address".

 

 

在默认情况下,<nested:nest>标签的property属性为当前ActionForm Bean的某个属性,或者为於上层<nested:nest>标签对应的JavaBean的某个属性,可以使用<nested:root>标签来显式指定顶层级别的JavaBean,<nested:root>标签的name属性指定JavaBean的名字,嵌套在<nested:root>标签中的<nested:nest>标签的property属性为这个JavaBean的某个属性。

 

和其他标签库中的标签功能相同的Nested标签

 

许多Nestd标签库中的标签具有和其他标签库中的标签相同的功能,区别在于Nested标签库中的标签属性相对于当前的嵌套级别,例如

<nested:nest property = "person"> Last name :<nested:text property="lastName"/> </nested:nest>

 

上面的<nested:text>标签和<html:text>标签具有相同的功能,都可以生成文本框,两者的区别在于<nested:text>标签的property属性为於当前嵌套级别对应的JavaBean的某个属性,而<html:text>标签的property属性为於当前表单对应的ActionForm Bean的某个属性。

 

3.Tiles框架。

    相比于<jsp:include 来讲,可以更大程度上的减少jsp代码,达到页面公用,并且页面统一的效果。

    使用的是模板原理。模板之间还可以使用继承,可以更加减少jsp代码。

转载请注明原文地址: https://www.6miu.com/read-5046196.html

最新回复(0)