做了一个DWR的验证和eXtremeTable的应用的例子
前期的系统创建、struts、hibernate、spring的集成工作就不用说了,一路下来…………
主要看DWR的应用,它用于表单验证:
1、先看它的配置:
(1)在web.xml里加上:
xml 代码
- <servlet>
- <servlet-name>dwr-invokerservlet-name>
- <servlet-class>uk.ltd.getahead.dwr.DWRServletservlet-class>
- <init-param>
- <param-name>debugparam-name>
- <param-value>trueparam-value>
- init-param>
- <load-on-startup>1load-on-startup>
- servlet>
-
- <servlet-mapping>
- <servlet-name>dwr-invokerservlet-name>
- <url-pattern>/dwr/*url-pattern>
- servlet-mapping>
-
(2)再建一个类,用于获取验证输出信息的属性文件,这个文件是参考了良葛格 的DWR 入門與應用(一)
里的Book代码
java 代码
- package test.common;
-
- import java.util.ResourceBundle;
-
- public class GetProperties{
- private ResourceBundle resource;
-
- public GetProperties()
- {
-
- resource = ResourceBundle.getBundle("dwrPro");
- }
-
- public String getDescription(String key)
- {
- return resource.getString(key);
- }
-
- }
(3)编写属性文件dwrPro_zh_CN.propertie(中文)和dwr_en.properties(英文)
java 代码
- username_hasUsed = 用户名已用,请选择别的用户名
- username_canUse = 恭喜!用户名可以使用
-
- username_hasUsed =username has used!
- username_canUse = username can use!
(4)配置dwr.xml,里面用了spring的bean 和java类
xml 代码
- <dwr>
-
- <allow>
- <create creator="spring" javascript="userManager">
- <param name="beanName" value="userManager"/>
- <include method="findUserIsExist"/>
- create>
-
- <create creator="new" javascript="User" scope="application">
- <param name="class" value="test.common.GetProperties"/>
- create>
- allow>
- dwr>
spring beanName 的value =“userManager”从applicationContext.xml里取得
xml 代码
- <bean id="userManagerTarget" class="test.spring.serviceImpl.UserServiceImpl">
- <property name="userDao">
- <ref bean="userDao"/>
- property>
- bean>
-
-
- <bean id="userManager" class="org.springframework.aop.framework.ProxyFactoryBean">
- <property name="proxyInterfaces">
- <value>test.spring.service.IUserServicevalue>
- property>
- <property name="interceptorNames">
- <list>
- <idref bean="transactionInterceptor"/>
- <idref bean="userManagerTarget"/>
- list>
- property>
- bean>
这里应该大家都懂,就不罗嗦了
(5)配好了这些,就可以在页面里用了
java 代码
-
-
-
- "-//W3C//DTD HTML 4.01 Transitional//EN">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- "0">
-
-
|
Login:
-
|
"text" name="user.name" id="username" onblur="checkName()"/>"check_username">
-
-
-
|
Password:
-
|
"password" name="user.password" id="username" onblur="checkpassword()"/>"check_password">
-
-
- "2" align="center">
-
-
-
-
这里当填了Login框,当光标从输入框移开时就实行了
js 代码
- function checkName()
- {
- var username = document.userForm.username.value;
- userManager.findUserIsExist(username,callback);
- }
userManager.findUserIsExist(username,callback)时关键,这里就用了
读取dwr.xml的userManager,然后读取applicationContext.xml里userManager bean ,进而实行findUserIsExist方法。
posted on 2008-03-04 22:13
xyz 阅读(400)
评论(0) 编辑 收藏 所属分类:
网络文摘