dwr整合ssh的xml配置方式

前端之家收集整理的这篇文章主要介绍了dwr整合ssh的xml配置方式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

struts2.0,spring2.5,hibernate3.0,dwr3.0.

web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  3. <welcome-file-list>
  4. <welcome-file>index.jsp</welcome-file>
  5. </welcome-file-list>
  6. <context-param>
  7. <param-name>contextConfigLocation</param-name>
  8. <param-value>classpath:applicationContext.xml</param-value>
  9. </context-param>
  10. <!-- 对Spring容器进行实例化 -->
  11. <listener>
  12. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  13. </listener>
  14. <filter>
  15. <filter-name>struts2</filter-name>
  16. <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  17. </filter>
  18. <filter-mapping>
  19. <filter-name>struts2</filter-name>
  20. <url-pattern>/*</url-pattern>
  21. </filter-mapping>
  22. **<servlet>
  23. <!-- 指定DWR核心Servlet的名字 -->
  24. <servlet-name>dwr-invoker</servlet-name>
  25. <servlet-class>
  26. <!-- 指定DWR核心Servlet的实现类 -->
  27. <!-- org.directwebremoting.servlet.DwrServlet -->
  28. org.directwebremoting.spring.DwrSpringServlet
  29.  
  30. </servlet-class>
  31. <!-- 指定DWR核心Servlet处于调试状态 -->
  32. <init-param>
  33. <param-name>debug</param-name>
  34. <param-value>true</param-value>
  35. </init-param>
  36. <load-on-startup>1</load-on-startup>
  37. </servlet>
  38. <!-- 指定核心Servlet的URL映射 -->
  39. <servlet-mapping>
  40. <servlet-name>dwr-invoker</servlet-name>
  41. <url-pattern>/cyq/*</url-pattern>
  42. </servlet-mapping>**
  43. </web-app>

dwr.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr30.dtd">
  3.  
  4. <dwr>
  5. <allow>
  6. <create creator="spring" javascript="menuSelect" >
  7.  
  8. <param name="beanName" value="com.action.MyAction" />
  9. </create>
  10.  
  11. <convert converter="bean" match="com.beans.Menu" />
  12. </allow>
  13.  
  14. </dwr>

注意:dwr.xml的 要与页面引入的js文件名一致,比如,切要与spring配置文件里的标签引入的js名一致,见如下的配置。

beans.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
  3.  
  4. <context:annotation-config />
  5. <!-- DWR 配置开始 -->
  6.  
  7. <dwr:configuration></dwr:configuration><!-- 必须要configuration -->
  8. <dwr:controller id="dwrController" debug="true" />
  9. <!-- DWR 配置结束 -->
  10.  
  11. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  12. <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
  13. <property name="url" value="jdbc:oracle:thin:@172.16.40.132:1521:localorc" />
  14. <property name="username" value="hr" />
  15. <property name="password" value="hr" />
  16. <!-- 连接池启动时的初始值 -->
  17. <property name="initialSize" value="1" />
  18. <!-- 连接池的最大值 -->
  19. <property name="maxActive" value="500" />
  20. <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
  21. <property name="maxIdle" value="2" />
  22. <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
  23. <property name="minIdle" value="1" />
  24. </bean>
  25. <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionfactorybean">
  26. <property name="dataSource" ref="dataSource" />
  27. <property name="mappingResources">
  28. <list>
  29. <value>com/lc/domain/operator.hbm.xml</value>
  30. </list>
  31. </property>
  32. <property name="hibernateProperties">
  33. <value>
  34. hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
  35. hibernate.hbm2ddl.auto=update
  36. hibernate.show_sql=false
  37. hibernate.format_sql=false
  38. hibernate.cache.use_second_level_cache=true
  39. hibernate.cache.use_query_cache=false
  40. hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
  41. </value>
  42. </property>
  43. </bean>
  44. <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  45. <property name="sessionFactory" ref="sessionFactory" />
  46. </bean>
  47. <tx:annotation-driven transaction-manager="txManager" />
  48. <bean id="opeDaoImp" class="com.lc.dao.imp.OperatorDaoImp">
  49. <property name="sessionFactory">
  50. <ref bean="sessionFactory"/>
  51. </property>
  52. </bean>
  53. <bean id="loginAction" class="com.lc.action.OperatorAction">
  54. <property name="opeDao">
  55. <ref bean="opeDaoImp"/>
  56. </property>
  57. <dwr:remote javascript="login"></dwr:remote>
  58. </bean>
  59.  
  60. </beans>

JSP页面

  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
  2. <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %>
  3.  
  4. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  5. <html>
  6. <head>
  7. <base href="<%=basePath%>">
  8.  
  9. <title>My JSP 'EnterGroup.jsp' starting page</title>
  10.  
  11. <Meta http-equiv="pragma" content="no-cache">
  12. <Meta http-equiv="cache-control" content="no-cache">
  13. <Meta http-equiv="expires" content="0">
  14. <Meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  15. <Meta http-equiv="description" content="This is my page">
  16.  
  17. <script type='text/javascript' src='cyqdwr/engine.js'></script>
  18. <script type='text/javascript' src='cyqdwr/util.js'></script>
  19. <script type='text/javascript' src='cyqdwr/interface/menuSelect.js'></script>
  20. <script type="text/javascript"> var i = 1; function addRow() { var tdValue = document.getElementById("td1").firstChild.nodeValue; var oTab = document.getElementById("myTab"); var oTr = document.createElement('tr');//创建一个tr //创建第一个td var otd = document.createElement('td'); otd.innerHTML = tdValue; oTr.appendChild(otd);//将td插入tr //创建第二个td var otd = document.createElement('td'); otd.innerHTML = "<input type='text' name='menus.groupName'>"; oTr.appendChild(otd);//将td插入tr oTab.tBodies[0].appendChild(oTr);//将整个tr插入到表格中 i++; } </script>
  21. <script type="text/javascript"> function flashSel(){ menuSelect.flushMenu(); } </script>
  22. </head>
  23.  
  24. <body onload="dwr.engine.setActiveReverseAjax(true),flashSel();">
  25. <span>菜单录入界面</span>
  26. <form action="Enter_addMenu" method="get">
  27. <table id="myTab">
  28. <tr>
  29. <td id="td1">菜单名称</td>
  30. <td><input type="text" name="menus.menuName"></td>
  31. </tr>
  32. <tr>
  33. <td id="td1">菜单URL</td>
  34. <td><input type="text" name="menus.menuURL"></td>
  35. </tr>
  36. <tr>
  37. <td id="td1">菜单</td>
  38. <td><select id="menuSelect">
  39.  
  40. </select> <input type="text" name="menus.menu"></td>
  41. </tr>
  42. </table>
  43. <input type="button" value="增加菜单" onclick="addRow()"> <input type="submit" value="录入" onclick="sub()">
  44. </form>
  45. </body>
  46. </html>

猜你在找的Ajax相关文章