关闭

dwr整合ssh的xml配置方式

标签: dwrsshxml
218人阅读 评论(0) 收藏 举报
分类:

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

web.xml

    <?xml version="1.0" encoding="UTF-8"?>  
    <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">  
      <welcome-file-list>  
        <welcome-file>index.jsp</welcome-file>  
      </welcome-file-list>  
       <context-param>  
           <param-name>contextConfigLocation</param-name>  
           <param-value>classpath:applicationContext.xml</param-value>  
        </context-param>  
      <!-- 对Spring容器进行实例化 -->  
        <listener>  
              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
        </listener>  
      <filter>  
        <filter-name>struts2</filter-name>  
         <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>  
      </filter>  
      <filter-mapping>  
            <filter-name>struts2</filter-name>  
            <url-pattern>/*</url-pattern>  
       </filter-mapping>  
        **<servlet>  
        <!-- 指定DWR核心Servlet的名字 -->  
           <servlet-name>dwr-invoker</servlet-name>  
           <servlet-class>  
        <!-- 指定DWR核心Servlet的实现类 -->  
        <!--   
            org.directwebremoting.servlet.DwrServlet 
         -->  
            org.directwebremoting.spring.DwrSpringServlet     

           </servlet-class>  
        <!-- 指定DWR核心Servlet处于调试状态 -->  
           <init-param>  
            <param-name>debug</param-name>  
            <param-value>true</param-value>  
           </init-param>  
           <load-on-startup>1</load-on-startup>  
        </servlet>  
        <!-- 指定核心Servlet的URL映射 -->  
        <servlet-mapping>  
           <servlet-name>dwr-invoker</servlet-name>  
           <url-pattern>/cyq/*</url-pattern>  
        </servlet-mapping>**  
    </web-app>  

dwr.xml

 <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr30.dtd">  

    <dwr>  
        <allow>  
            <create creator="spring" javascript="menuSelect" >  

                <param name="beanName" value="com.action.MyAction" />  
            </create>  

            <convert converter="bean" match="com.beans.Menu" />  
        </allow>  

    </dwr>  

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

beans.xml

<?xml version="1.0" encoding="UTF-8"?>  
    <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">  

        <context:annotation-config />  
         <!-- DWR 配置开始 -->     

       <dwr:configuration></dwr:configuration><!-- 必须要configuration -->       
        <dwr:controller id="dwrController" debug="true" />       
       <!-- DWR 配置结束 -->            

        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
            destroy-method="close">  
            <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />  
            <property name="url"  
                value="jdbc:oracle:thin:@172.16.40.132:1521:localorc" />  
            <property name="username" value="hr" />  
            <property name="password" value="hr" />  
             <!-- 连接池启动时的初始值 -->  
            <property name="initialSize" value="1" />  
             <!-- 连接池的最大值 -->  
            <property name="maxActive" value="500" />  
             <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->  
            <property name="maxIdle" value="2" />  
             <!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->  
            <property name="minIdle" value="1" />  
        </bean>  
        <bean id="sessionFactory"  
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
            <property name="dataSource" ref="dataSource" />  
            <property name="mappingResources">  
                <list>  
                    <value>com/lc/domain/operator.hbm.xml</value>  
                </list>  
            </property>  
            <property name="hibernateProperties">  
                <value>  
                    hibernate.dialect=org.hibernate.dialect.Oracle9Dialect  
                    hibernate.hbm2ddl.auto=update  
                    hibernate.show_sql=false  
                    hibernate.format_sql=false  
                    hibernate.cache.use_second_level_cache=true  
                    hibernate.cache.use_query_cache=false  
                    hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider  
                  </value>  
            </property>  
        </bean>  
        <bean id="txManager"  
            class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
            <property name="sessionFactory" ref="sessionFactory" />  
        </bean>  
        <tx:annotation-driven transaction-manager="txManager" />  
        <bean id="opeDaoImp" class="com.lc.dao.imp.OperatorDaoImp">  
            <property name="sessionFactory">  
                <ref bean="sessionFactory"/>  
            </property>  
        </bean>  
        <bean id="loginAction" class="com.lc.action.OperatorAction">  
            <property name="opeDao">  
                <ref bean="opeDaoImp"/>  
            </property>    
            <dwr:remote javascript="login"></dwr:remote>   
        </bean>  

    </beans>  

JSP页面:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"
    contentType="text/html; charset=utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'EnterGroup.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<script type='text/javascript' src='cyqdwr/engine.js'></script>
<script type='text/javascript' src='cyqdwr/util.js'></script>
<script type='text/javascript' src='cyqdwr/interface/menuSelect.js'></script>
<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>
 <script type="text/javascript">
 function flashSel(){
 menuSelect.flushMenu();
 }

 </script>
</head>

<body onload="dwr.engine.setActiveReverseAjax(true),flashSel();">
    <span>菜单录入界面</span>
    <form action="Enter_addMenu" method="get">
        <table id="myTab">
            <tr>
                <td id="td1">菜单名称</td>
                <td><input type="text" name="menus.menuName"></td>
            </tr>
            <tr>
                <td id="td1">菜单URL</td>
                <td><input type="text" name="menus.menuURL"></td>
            </tr>
            <tr>
                <td id="td1">父菜单</td>
                <td><select id="menuSelect">

                </select> <input type="text" name="menus.menu"></td>
            </tr>
        </table>
        <input type="button" value="增加菜单" onclick="addRow()"> <input
            type="submit" value="录入" onclick="sub()">
    </form>
</body>
</html>
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:223805次
    • 积分:4345
    • 等级:
    • 排名:第6928名
    • 原创:215篇
    • 转载:36篇
    • 译文:0篇
    • 评论:36条
    文章分类
    最新评论