SSH+DWR配置

http://blog.csdn.net/shibingli/article/details/5309694


项目所需要用的包(包含常用包):

 antlr-2.7.6.jar
 aopalliance-1.0.jar
 asm-all-3.2.jar
 cglib-2.2.jar
 commons-beanutils-1.8.2.jar
 commons-codec-1.4.jar
 commons-collections-3.2.1.jar
 commons-digester-2.0.jar
 commons-fileupload-1.2.1.jar
 commons-io-1.4.jar
 commons-lang-2.4.jar
 commons-logging-1.1.1.jar
 commons-validator-1.3.1.jar
 dom4j-1.7.jar
 dwr-2.06.jar
 ehcache-1.2.3.jar
 ejb3-persistence.jar
 ezmorph-1.0.3.jar
 freemarker-2.3.15.jar
 hibernate-annotations.jar
 hibernate-commons-annotations.jar
 hibernate-entitymanager.jar
 hibernate-search-3.1.1.GA.jar
 hibernate-validator-4.0.2.GA.jar
 hibernate3.jar
 jakarta-oro-2.0.8.jar
 javassist-3.9.0.GA.jar
 json-lib-2.3-jdk15.jar
 jstl.jar
 jta-1.1.jar
 jtds-1.2.5.jar
 junit-4.8.1.jar
 log4j-1.2.8.jar
 ognl-2.7.3.jar
 org.springframework.aop-3.0.0.RELEASE.jar
 org.springframework.asm-3.0.0.RELEASE.jar
 org.springframework.aspects-3.0.0.RELEASE.jar
 org.springframework.beans-3.0.0.RELEASE.jar
 org.springframework.context-3.0.0.RELEASE.jar
 org.springframework.context.support-3.0.0.RELEASE.jar
 org.springframework.core-3.0.0.RELEASE.jar
 org.springframework.expression-3.0.0.RELEASE.jar
 org.springframework.instrument-3.0.0.RELEASE.jar
 org.springframework.instrument.tomcat-3.0.0.RELEASE.jar
 org.springframework.jdbc-3.0.0.RELEASE.jar
 org.springframework.jms-3.0.0.RELEASE.jar
 org.springframework.orm-3.0.0.RELEASE.jar
 org.springframework.oxm-3.0.0.RELEASE.jar
 org.springframework.test-3.0.0.RELEASE.jar
 org.springframework.transaction-3.0.0.RELEASE.jar
 org.springframework.web-3.0.0.RELEASE.jar
 org.springframework.web.portlet-3.0.0.RELEASE.jar
 org.springframework.web.servlet-3.0.0.RELEASE.jar
 org.springframework.web.struts-3.0.0.RELEASE.jar
 poi-3.5-FINAL-20090928.jar
 proxool-0.9.1.jar
 proxool-cglib.jar
 pull-parser-2.1.10.jar
 slf4j-api-1.5.10.jar
 slf4j-log4j12-1.5.10.jar
 slf4j-nop-1.5.10.jar
 standard.jar
 struts2-convention-plugin-2.1.8.1.jar
 struts2-core-2.1.8.1.jar
 struts2-dwr-plugin-2.1.8.1.jar
 struts2-json-plugin-2.1.8.1.jar
 struts2-spring-plugin-2.1.8.1.jar
 velocity-1.5.jar
 velocity-tools-1.3.jar
 xwork-core-2.1.6.jar


proxool(proxool.properties)配置文件:

 jdbc-0.proxool.alias=DBPool
 jdbc-0.proxool.driver-url=jdbc:jtds:sqlserver://localhost:1433/student
 jdbc-0.proxool.driver-class=net.sourceforge.jtds.jdbc.Driver
 jdbc-0.user=sa
 jdbc-0.password=**********      (哈哈,密码省略)
 jdbc-0.proxool.house-keeping-sleep-time=40000
 jdbc-0.proxool.house-keeping-test-sql=SELECT GETDATE()
 jdbc-0.proxool.maximum-connection-count=100
 jdbc-0.proxool.minimum-connection-count=25
 jdbc-0.proxool.maximum-connection-lifetime=18000000
 jdbc-0.proxool.simultaneous-build-throttle=5
 jdbc-0.proxool.recently-started-threshold=40000
 jdbc-0.proxool.overload-without-refusal-lifetime=50000
 jdbc-0.proxool.maximum-active-time=60000
 jdbc-0.proxool.verbose=true
 jdbc-0.proxool.trace=true
 jdbc-0.proxool.fatal-sql-exception=Fatal error
 jdbc-0.proxool.prototype-count=2
 jdbc-0.proxool.statistics-log-level=ERROR
 jdbc-0.proxool.test-before-use=true
 jdbc-0.proxool.test-after-use=true


DWR(dwr.xml)配置文件:

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd ">
 <dwr>
  <allow>
   <create creator="spring" javascript="dwrTest">
    <param name="beanName" value="dwrTest" />   <!--Spring配置文件中的bean:aclManager -->
   </create>
  </allow>
 </dwr>


项目配置文件(web.xml)配置文件:

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
  xmlns="http://java.sun.com/xml/ns/javaee " xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
  id="WebApp_ID" version="2.5">
  <display-name>sshdwr</display-name>
  <welcome-file-list>
   <welcome-file>index.html</welcome-file>
  </welcome-file-list>
 
  <!-- 页面不存在  -->
  <error-page>
   <error-code>404</error-code>
   <location>/pagenotfound.html</location>
  </error-page>

  <!-- 错误页面 -->
  <error-page>
   <exception-type>java.lang.Exception</exception-type>
   <location>/error.html</location>
  </error-page>

  <!-- spring配置文件读取路径-->
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>

  <!--增加spring监听(载入Spring ApplicationContext )-->
  <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- 扩展spring bean的作用域有request,session,global session等-->
  <listener>
   <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>

  <!-- Spring 刷新Introspector防止内存泄露 -->
  <listener>
   <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>

  <!-- spring的session管理-->
  <filter>
   <filter-name>openSessionInViewFilter</filter-name>
   <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

   <init-param>
    <param-name>sessionFactoryBeanName</param-name>
    <param-value>sessionFactory</param-value>
   </init-param>

   <init-param>
    <param-name>singleSession</param-name>
    <param-value>true</param-value>
   </init-param>
  </filter>

  <filter-mapping>
   <filter-name>openSessionInViewFilter</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!--struts2.1.8配置-->
  <filter>
   <filter-name>struts2</filter-name>
   <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>

  <filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- proxool的web监控-->
  <servlet>
   <servlet-name>admin</servlet-name>
   <servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
  </servlet>
  <servlet-mapping>
   <servlet-name>admin</servlet-name>
   <url-pattern>/admin</url-pattern>
  </servlet-mapping>

  <!-- DWR配置-->
  <servlet>
   <servlet-name>dwr</servlet-name>
   <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
   <init-param>
    <param-name>debug</param-name>
    <param-value>true</param-value>
   </init-param>
   <init-param>
    <param-name>scriptCompressed</param-name>
    <param-value>false</param-value>
   </init-param>
   <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
   <servlet-name>dwr</servlet-name>
   <url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>
 </web-app>


Spring(applicationContext.xml)配置文件:

 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans "
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance " xmlns:jee="http://www.springframework.org/schema/jee "
  xmlns:tx="http://www.springframework.org/schema/tx " xmlns:context="http://www.springframework.org/schema/context "
  xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
   http://www.springframework.org/schema/jee
   http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd ">

  <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="location" value="/WEB-INF/hibConfig.properties" />
  </bean>

  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="mappingResources">
    <list>
     <value>com/loverit/project/test/entity/Person.hbm.xml</value>
     <value>com/loverit/project/test/entity/Sex.hbm.xml</value>
    </list>
   </property>

   <property name="hibernateProperties">
    <props>
     <prop key="hibernate.dialect">${hibernate.dialect}</prop>
     <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
     <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
     <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
     <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
    
     <!--
      <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
     -->
    
     <!-- proxool连接池 -->
     <prop key="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</prop>
     <prop key="hibernate.proxool.properties">proxool.properties</prop>
     <prop key="hibernate.proxool.pool_alias">DBPool</prop>

    </props>
   </property>

  </bean>

  <!-- 定义事务管理 -->
  <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory"  ref="sessionFactory" />
  </bean>

  <!-- 定义事务管理拦截器 -->
  <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
   <property name="transactionManager" ref="transactionManager" />
   <property name="transactionAttributes">
    <props>
     <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
     <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
   </property>
  </bean>

  <!-- 定义代理自动管理事务 -->
  <bean id="ProxyCreator"  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
 
   <!-- 指定需要Spring管理事务的Bean -->
   <property name="beanNames">
    <list>
     <value>testService</value>
    </list>
   </property>
   <!-- 调用事务管理拦截器 -->
   <property name="interceptorNames">
    <list>
     <value>transactionInterceptor</value>
    </list>
   </property>
  </bean>
 
  <!-- 测试类(本例未用到) -->
  <bean id="dao" class="com.loverit.framework.dao.DaoImpl">
   <property name="sessionFactory" ref="sessionFactory" />
  </bean>

  <bean id="testService" class="com.loverit.project.test.service.TestService">
   <property name="dao" ref="dao" />
  </bean>

  <bean id="testAction" class="com.loverit.project.test.action.TestAction"  scope="prototype">
   <property name="testService" ref="testService" />
  </bean>

  <!-- DWR测试类 -->
  <bean id="dwrTest" class="com.loverit.project.test.action.DwrTest" >
  </bean>
 </beans>


struts(struts.xml)配置文件:

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd ">

 <struts>
  <include file="struts-default.xml" />

  <package name="mytest" extends="struts-default,json-default">
   <action name="tt" class="testAction">
    <result name="query" type="dispatcher">/default.jsp</result>
    <result name="reload"  type="redirect">/tt.action</result>
   </action>
  </package>
 
 </struts>

struts(struts.properties)文本配置文件:

 #是否为struts的开发模式
 struts.devMode=false
 #用URL扩展名来确定是否这个请求是被用作Struts action,其实也就是设置 action的后缀,例如login.do的'do'字。
 struts.action.extension=action
 ##指定Struts 2默认的ObjectFactory Bean,该属性默认值是spring
 struts.objectFactory = spring
 ##指定Spring框架的自动装配模式,该属性的默认值是name,即默认根据Bean的name属性自动装配
 struts.objectFactory.spring.autoWire = name
 ##该属性指定整合Spring框架时,是否缓存Bean实例,该属性只允许使用true和false两个属性值,它的默认值是true。通常不建议修改该属性值。
 struts.objectFactory.spring.useClassCache = true
 #是否加载xml配置(true,false)
 struts.configuration.xml.reload=true
 #国际化信息内码
 struts.i18n.encoding = utf-8
 #是否可以用替代的语法替代tags
 struts.tag.altSyntax=true
 # 不让标签自动生成html代码(没有用的,不可控的)
 struts.ui.theme = simple

log4j(log4j.properties)配置文件:

#是否为struts的开发模式
struts.devMode=false
#用URL扩展名来确定是否这个请求是被用作Struts action,其实也就是设置 action的后缀,例如login.do的'do'字。
struts.action.extension=action
##指定Struts 2默认的ObjectFactory Bean,该属性默认值是spring
struts.objectFactory = spring
##指定Spring框架的自动装配模式,该属性的默认值是name,即默认根据Bean的name属性自动装配
struts.objectFactory.spring.autoWire = name
##该属性指定整合Spring框架时,是否缓存Bean实例,该属性只允许使用true和false两个属性值,它的默认值是true。通常不建议修改该属性值。
struts.objectFactory.spring.useClassCache = true
#是否加载xml配置(true,false)
struts.configuration.xml.reload=true
#国际化信息内码
struts.i18n.encoding = utf-8
#是否可以用替代的语法替代tags
struts.tag.altSyntax=true
# 不让标签自动生成html代码(没有用的,不可控的)
struts.ui.theme = simple


Hibernate(hibConfig.properties)配置文件(此配置参数可以直接在applicationContext.xml中配置,根据个人习惯此处本人单独配置):     

 hibernate.dialect=org.hibernate.dialect.SQLServerDialect
 hibernate.show_sql=true
 hibernate.jdbc.batch_size=20
 hibernate.cache.use_query_cache=true
 hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
 hibernate.hbm2ddl.auto=update

Hibernate (ehcache.xml)缓存配置:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache>

 <!--  设置cache.data文件存放位置   -->
 <diskStore path="D://cache" />

 <!-- eternal 表示缓存是不是永远不超时 -->
 <!--
  timeToLiveSeconds是缓存中每个元素(这里也就是一个POJO)的超时时间
  ,如果eternal="false",超过指定的时间,这个元素就被移走了。
 -->
 <!--
  timeToIdleSeconds是发呆时间,是可选的。当往缓存里面put的元素超过500个时,如果overflowToDisk="true",就会把缓存中的部分数据保存在硬盘上的临时文件里面。
 -->
 <defaultCache maxElementsInMemory="3" eternal="false"
  overflowToDisk="true" timeToIdleSeconds="120" timeToLiveSeconds="120"
  diskPersistent="false" diskExpiryThreadIntervalSeconds="120" />
</ehcache>

DWR(DwrTest.java)测试类:

 public class DwrTest
 {
  public String test (String str)
  {
   System.out.println ("测试DWR!") ;
   return "测试DWR:"+ str;
  }
 }


JSP测试文件(default.jsp):

 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd ">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>测试DWR</title>
 <script type='text/javascript' src='${pageContext.request.contextPath }/dwr/interface/dwrTest.js'></script>
 <script type='text/javascript' src='${pageContext.request.contextPath }/dwr/engine.js'></script>
 <script type='text/javascript' src='${pageContext.request.contextPath }/dwr/util.js'></script>
 </head>
 <body>
 <a href="javascript:onTest();">测试DWR!</a>
 </body>
 <script type="text/javascript">
  function onTest()
  {
   dwrTest.test("测试数据!", function(data)
   {
    alert(data);
   });
  }
 </script>
 </html>

 

你可能感兴趣的:(ssh+DWR)