前端之家收集整理的这篇文章主要介绍了
DWR+hibernate+spring,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1.集成Spring和Hibernate 2.测试 3.
添加dwr的jar
文件 4.在Web.xml中配置DwrServlet <servlet> <servlet-name>dwrServlet</servlet-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwrServlet</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> 5.在WEB-INF下
添加dwr.xml <dwr> <allow> <!--创建器:spring--> <create creator="spring" javascript="JUser"> <!--value="spring中bean的id"--> <param name="beanName" value="userBiz"></param> <include method="checkExistName"/> </create> </allow> </dwr> 6.测试:http://localhost:8080/项目名/dwr/ 7.编写
页面,并在
页面上
调用dwr <script type='text/javascript' src='/dwrDemo/dwr/engine.js'></script> <script type='text/javascript' src='/dwrDemo/dwr/interface/JUser.js'></script> <script type='text/javascript' src='/dwrDemo/dwr/util.js'></script> <script type="text/javascript"> function checkUserName(){ //document.getElementById("uname"); var uname = $("uname").value; //alert(uname) //JUser为dwr.xml中create节点中javascript
属性的值 //checkExistName为dwr.xml中include节点中method
属性的值,callBack回调
函数的
名称 JUser.checkExistName(uname,callBack); } function callBack(data){ if(data){ //alert("
用户名已存在!"); $("result").innerHTML="<font color=red>
用户名已存在!</font>"; }else{ //alert("
用户名可用!"); $("result").innerHTML="<font color=green>
用户名可用!</font>"; } } </script>
原文链接:https://www.f2er.com/ajax/165440.html