niyue

Archive for January, 2005|Monthly archive page

Struts中进行数据验证

In java on January 30, 2005 at 8:22 AM

Developer STRUTS

Check Your Form with Validator

By James Holmes

Enabling the Validator Plug-in

配置Validator插件,也即在配置struts-config.xml,加入该插件

Configuring validator-rules.xml

大多数情况下你不需要修改预定义的验证规则,除非你希望给框架自定义验证规则。

Included Validations

默认情况下已经包含了一些常用的验证器,如required,CreditCard和email等

Creating Form Beans

为了使用验证器,应用中的Form Bean应该是验证器ActionForm的子类,
而不能是ActionFrom本身。这一子类提供了ActionForm的validate()方法的一个实现。Form Bean继承了子类之后并不需要将验证进行硬编码,完全可以将这一方法忽略掉。验证器会帮你提供验证需要的代码。
form bean在struts-config.xml中的配置也同常规的Form Bean相同验证的时候配置validation.xml。两种标准的方式创建Form Bean。一种是创建一个具体的Form Bean,另一种是创建一个动态的Form Bean,validator.xml的Form Bean的验证与struts-config.xml中的Form Bean一对一的绑定,这种机制可以适用于绝大多数的情况,但是当Form Bean在多个Action间复用(可能有的用的字段多一些有的用的少一些)时,就不适用了。为了解决这一问题,验证器有两个子类ValidatorActionForm和DynaValidatorActionForm允许将验证与action进行绑定而不是与Form Bean进行绑定。

Configuring validation.xml

Configuring ApplicationResources.properties

验证器使用Struts的资源束机制来显示错误消息。主要配置ApplicationResource.properties(添加消息文本和对应的key)文件和validation.xml(利用key引用消息文本)文件。

如果不想使用资源束机制的话,也可以在validation.xml文件中直接表明。

Enabling Client-Side Validations

除了服务端的数据验证,Struts还有机制支持客户端验证。
在validator-rules.xml中标明了在客户端用于验证的JavaScript代码(可选的标明)
为了使用客户端验证,就要在每个需要验证的JSP插入Struts HTML标签库的JavaScript标签。而无论是否使用客户端验证,服务端验证都会进行。

其他的一些文章:

Struts Validator验证器使用指南(推荐阅读)

在struts中使用validator做页面验证

Struts Validator的使用

DriverManagerDataSource in Spring Framework

In programming on January 29, 2005 at 3:38 PM

DriverManagerDataSource in Spring Framework

javax.sql Interface DataSource

今天看了一天的spring,想使用里面提供的JdbcTemplate,看上去非常酷的样子,不过其中涉及到了一个DataSource接口,不知道干嘛的,好不容易才找到了一个讲的比较清楚的解释。

Implementation of SmartDataSource that configures a plain old JDBC Driver via bean properties, and returns a new Connection every time.

Useful for test or standalone environments outside of a J2EE container, either as a DataSource bean in a respective ApplicationContext, or in conjunction with a simple JNDI environment. Pool-assuming Connection.close() calls will simply close the connection, so any DataSource-aware persistence code should work.

In a J2EE container, it is recommended to use a JNDI DataSource provided by the container. Such a DataSource can be exported as a DataSource bean in an ApplicationContext via JndiObjectFactoryBean, for seamless switching to and from a local DataSource bean like this class.

If you need a “real” connection pool outside of a J2EE container, consider Apache’s Jakarta Commons DBCP. Its BasicDataSource is a full connection pool bean, supporting the same basic properties as this class plus specific settings. It can be used as a replacement for an instance of this class just by changing the class name of the bean definition to “org.apache.commons.dbcp.BasicDataSource”.

“http session”的定义

In programming on January 28, 2005 at 6:44 AM

HTTP State Management Mechanism

STATE AND SESSIONS

This document describes a way to create stateful sessions with HTTP requests and responses. Currently, HTTP servers respond to each client request without relating that request to previous or subsequent requests; the technique allows clients and servers that wish to exchange state information to place HTTP requests and responses within a larger context, which we term a “session”. This context might be used to create, for example, a “shopping cart”, in which user selections can be aggregated before purchase, or a magazine browsing system, in which a user’s previous reading affects which offerings are presented.

There are, of course, many different potential contexts and thus many different potential types of session. The designers’ paradigm for sessions created by the exchange of cookies has these key attributes:

1. Each session has a beginning and an end.

2. Each session is relatively short-lived.

3. Either the user agent or the origin server may terminate a session.

4. The session is implicit in the exchange of state information.

Struts中谈到的session

2.2 JavaBeans and Scope

Within a web-based application, JavaBeans can be stored in (and accessed from) a number of different collections of “attributes”. Each collection has different rules for the lifetime of that collection, and the visibility of the beans stored there. Together, the rules defining lifetime and visibility are called the scope of those beans. The JavaServer Pages (JSP) Specification defines scope choices using the following terms (with the equivalent servlet API concept defined in parentheses):

  • page – Beans that are visible within a single JSP page, for the lifetime of the current request. (Local variables of the service method)
  • request – Beans that are visible within a single JSP page, as well as to any page or servlet that is included in this page, or forwarded to by this page. (Request attributes)
  • session – Beans that are visible to all JSP pages and servlets that participate in a particular user session, across one or more requests. (Session attributes)
  • application – Beans that are visible to all JSP pages and servlets that are part of a web application. (Servlet context attributes)

附录一篇:

Session详解

作者:郎云鹏(dev2dev ID: hippiewolf)

学习Struts

In java, learning on January 28, 2005 at 2:34 AM

最近不断在看Struts方面的资料,应该说Struts已经是很成熟的一种技术了,在网上的相关介绍也是连篇累牍,但是看了能够增进理解有所帮助的还是比较难见到。下面是我觉得在Struts学习中对我有帮助的一些资料:

下面是我学习中遇到的一些困难及解决:

    • 在Tomcat上部署Struts的例子的时候碰到了问题,解决:Unable to find a javac compiler
    • 表单数据验证失败时发生错误,“No input attribute for mapping path”,原因是没有填写配置文件action中的input属性值。解决:Struts中不同的Action和ActionForm组合
    • 两次输入密码比较的验证,解决:Struts Validator: Validating Two Fields Match by Matt Raible. Howto article.开始漏看了最后一句重要的话,没看完就开始了,结果因为那个小问题浪费了两个多小时,真是不值得。
    • 实现下拉框时出现错误”Cannot find bean under name org.apache.struts.taglib.html.BEAN”。解决:JSP FAQ @ jGuru
    • 部署新的action时发生错误”No Action Instance for Path /CreateContent could be created”,开始在网上找了一下,发现大多数此类错误都是由于Action的type名称写错了,但是我仔细核对发现这里没有错,我的错误在于没有将Action的type类声明成public的!
    • 上面的数据验证的例子中采用的API调用已经被deprecated掉了,Struts 1.2用也还可以用,但是Eclipse里面会出来感叹号说不赞成使用ValidatorUtil和Resources.getActionError()方法,解决:Struts Upgrade Notes 11 to 124
    • 开了一个新的sample应用的时候,出现异常java.lang.IllegalArgumentException: Resources cannot be null.
      at org.apache.commons.validator.Validator.(Validator.java:188)
      后来发现是strut
      中没有添加validator插件,同时validation.xml文件和validator-rules.xml文件不存在
    • 使用Struts将应用分成为几个模块配置的时候,无论如何配置,一直出现找不到子模块中的action的异常,”Cannot retrieve mapping for action /mindforce/SubmitLogon”.后来发现原来是tab的链接没有通过action进行转发,而是直接写了要显示的jsp页面视图的url,因此struts进行模块间转换时无法自动识别,故action mapping找不到对应的action.正确的配置方法是:子模块中的action路径均填写模块下的相对路径,jsp页面中的action也填写相对于模块的路径而不要加上模块名称,struts会自动在模块切换时添加模块名.模块切换方法请见:5.3.3 Switching Modules

进行Struts开发时一些有用的工具:

    • Scioworks™ Camino

      Visual Modelling Tool for Struts

      Scioworks™ Camino is a visual modelling tool for Jakarta Struts Framework, the de-facto J2EE web MVC framework. Designed for rapid assembly of web applications, its unique visual drag-and-connect paradigm allows for rapid development and re-wiring of web application with minimal coding.

Exadel Struts Studio now supports Eclipse 3.0.x. This version includes design-time JSP Preview, JSP, CSS, JavaScript and XML Prompting with autocomplete functionality, Java debugging of Web applications under the Tomcat, JBoss and Sun J2EE SDK environment, and one-step adding of Struts support to J2EE projects created with other Eclipse plug-ins.

    • JamesHolmes.com

Struts Console

The Struts Console is a FREE standalone Java Swing application for developing and managing Struts-based applications. With the Struts Console you can visually edit JSP Tag Library, Struts, Tiles and Validator configuration files.

The Struts Console also plugs into multiple, popular Java IDEs for seamless management of Struts applications from one central development tool.

FWA Software‘s Visual Tags Dreamweaver extension suites for JSTL and Struts enable web developers to use Macromedia’s Dreamweaver MX web design and development product to

  • Visually design, implement, and maintain web pages for JSTL and Struts-based web applications
  • Rapidly prototype web pages for JSTL and Struts-based web applications
  • Exploit open source technologies with Dreamweaver to create JSTL and Struts-based web applications

Eclipse Plugins

In java on January 27, 2005 at 4:37 PM

Eclipse Plugins

Java Server Faces Resources

In java, programming on January 21, 2005 at 1:45 PM

JamesHolmes.com
Java Server Faces Resources


Articles
Books
Blog Entries
Chats / Interviews
FAQs
Forums / Mailing Lists
In The News

Links
Presentations
Software – Components
Software – GUI Tools
Software – Implementations
Software – Miscellaneous
Tutorials

 

《I Love Lucene》总结

In java, programming on January 18, 2005 at 1:57 PM

前几天看到了TheServerSide上面的一篇文章I Love Lucene,感到对自己很有帮助,稍微总结了一下理理思路。

I Love Lucene

by Dion Almaer January 2005

Introduction

简要介绍了TheServerSite原来使用的搜索的方案,并由此引出Lucene

High level infrastructure

从高层介绍Lucene的方案,这一方案主要分成了两大部分,一部分是建立索引,另一部分是对索引进行搜索。分别介绍了这两部分的主要的接口IndexBuilderIndexSearch

Building the Index: Details of the index building process

全文最重要的一个组成部分。该部分介绍了以下四个内容:

1. 应该索引的字段

2. 索引的方式:增量索引、批量索引

3. 索引源的类型

4. 索引结果的rank

What fields should compromise our index?

讲了一下不同的索引字段使用的数据类型的问题

What types of indexing?

采用了增量索引和批量索引结合的方式,定义了一个增量索引的间隔,每隔这一间隔进行一次批量索引,在间隔内的时间内进行增量索引。同时还介绍了一下Lucene中如何删除索引记录。

What to index?

ThreadIndexSource

介绍对不同的索引源索引的问题,如对数据库中的数据索引以及对文件系统中的文件的索引。还介绍了一下索引TheServerSide的论坛中的帖子时引出的一个小技巧。

How to tweak the ranking of records?

对不同的字段赋以不同的权值来对一个文档进行较合理的rank

Searching the index

Lucene的使用主要看来是建立索引比较复杂,搜索索引极其简单,这里稍微花了一点篇幅就讲清了都,主要介绍了IndexSearch类中的search方法和查询解析类CustomQueryParser

Configuration: One place to rule them all

这部分主要介绍如何使用XML文件对搜索中的一些参数(如索引存放位置、字段权值等)进行动态配置,和Lucene其实没什么关系,主要还是说的是IoC(控制反转)的东西,讲了一下Apache Digester的使用。

XML Configuration File

Digester Rules File

Web Tier: TheSeeeeeeeeeeeerverSide?

用户搜索使用的Web界面,MVC结构。

SearchAssembler Web Action

根据用户输入构造查询语句,并讲查询语句交给IndexSearch处理,同时还负责封装查询结果。

Search View

表示层使用JSP ( for legacy reason)。根据TheServerSide上面的帖子回复,似乎说TheServerSide以后要用ApacheTapestry

Conclusion

总结,就是说Lucene很好。

Deployment Descriptor Elements and Tag Library Descriptor

In java on January 18, 2005 at 8:58 AM

下文涵盖了所有Servlet的部署描述符文件web.xml中各个元素的含义。

web.xml Deployment Descriptor Elements

下文讲述了如何创建一个Tag Library描述符的步骤以及Tag Library描述符中各个元素的含义。

Creating a Tag Library Descriptor

The following sections describe how to create a tag library descriptor (TLD) file:

Google计划组建全球光纤网络?

In other on January 18, 2005 at 1:48 AM

今天在CNet上面看到一篇文章,分析出Google计划利用光纤组建一个全球的网络。好像并没有什么有力的证据来证明这一结论,唯一的理由就是Google在招收这方面的人才,而Google的发言人又拒绝对这一情况作出评论。”Google is looking for Strategic Negotiator candidates with experience in…(i)dentification, selection, and negotiation of dark fiber contracts both in metropolitan areas and over long distances as part of development of a global backbone network,” the posting reads, in part.

不过是很奇怪,Google这样一个企业,如果发展了一个光纤网,那是要做什么?这些网络要是仅仅用于企业内部也太奢侈了;要说提供给用户使用,Google和电信企业抢生意,转变为信息服务提供商似乎不太可能,也很不合逻辑,好像应该解释为Google的某些新技术会用到大流量的数据交换,这又让人很容易想到视频或者音频方面的一些应用,但是,是什么呢?Google真是让人琢磨不透呀~

Google Logo Show

In other on January 17, 2005 at 3:40 PM

Athen2004Google出了好多新图标,本来想收集全的,不过今天在看的时候发现一个网站,集了好多的Google图标(自称是最全的),而且做的很好,没办法比过它了,直接就没兴趣再收集了

Netscape的用户请点击这里