欢迎光临
我们一直在努力

About Struts—(六)-JSP教程,面向对象/设计

建站超值云服务器,限时71元/月

 

3.3.4 automatic form validation
除了上面描述的,struts 提供了额外的校验form输入域的机制。使用这个机制,你需要重载actionform 类的下面这个方法:

public actionerrors
  validate(actionmapping mapping,
    httpservletrequest request);

the validate() method is called by the controller servlet after the bean properties have been populated, but before the corresponding action classs perform() method is invoked. the validate() method has the following options:
·   执行适当的校验,没有发现问题 – 返回null or a zero-length actionerrors 实例,然后controller servlet 将调用action类的perform() 方法。
·   执行适当的校验,发现问题 – 返回一个包含有actionerror的actionerrors 实例,actionerror中包含了应该被显示的error message keys 。the controller servlet will store this array as a request attribute suitable for use by the <html:errors> tag, and will forward control back to the input form (identified by the input property for this actionmapping).
正如前面所提到的,这个特征是可选的。缺省的validate() 方法将返回null, and the controller servlet 将假定校验工作由action 类来做。
一个一般的做法是在actionform的validate方法中执行简单的校验,然后在action类中进行"business logic"校验。
an optional package for performing actionform validations is available in the nightly build and from david winterfeldts web site.

3.4 other presentation techniques
虽然,你的应用程序的look and feel 可以完全基于标准jsp和struts custom tag构建,你还是应该考虑使用其他的有利于组件重用的技术,减少维护的精力,减少错误。几个可能的选择在下面的章节中被讨论。

3.4.1 application-specific custom tags
处理使用struts库提供的custom tags 外,你可以轻松的创建特定于你自己应用程序的tags来帮助你创建用户界面。示例程序创建了几个自己的tags:
·   checklogon – 检查某个会话对象是否存在,如果没有则将控制传递到登录页面。this is used to catch cases where a user has bookmarked a page in the middle of your application and tries to bypass logging on, or if the users session has been timed out.
·   linksubscription – generates a hyperlink to a details page for a subscription, which passes the required primary key values as request attributes. this is used when listing the subscriptions associated with a user, and providing links to edit or delete them.
·   linkuser – generates a hyperlink to a details page for a user, which passes the required primary key values as request attributes.

 

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » About Struts—(六)-JSP教程,面向对象/设计
分享到: 更多 (0)

相关推荐

  • 暂无文章