Dwr技术与ssh2的相关配置技术摘要

 

平台:win7 myeclipse10 struts2  hibernate 3.3 spring3.0javascript

相关重要文件:  web.xml  dwr.xml   dwr.js  engine.js  util.js   Common-logging.jar  java

ssh2的配置

1、引入struts2  hibernate3.3  spring 3.0 所需库

Spring3.0:

         Spring 3.0 AOP Librariesweb

         Spring 3.0 Core Librariesajax

         Spring 3.0 Persistence Core Librariesspring

         Spring 3.0 Persistence  JDBC  Librariessql

         Spring 3.0 Web Librariesapp

 

Hibernate 3.3:

         Hibernate  3.3  Annotations & Entity Managerless

         Hibernate  3.3  Core Librarieseclipse

 

Struts2.1:

         Struts 2 Core Librariesssh

         Struts 2 DWR Libraries

Struts 2 Spring Libraries

 

 2、编写配置文件

         1Struts.xml 中添加spring相关文件:

<constant name="struts.objectFactory" value="spring"></constant>

         2web.xml中添加监听器配置信息

<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>

3、为了可以直观化sql语句

hibernate.cfg.xml文件中添加

显示sql代码:

<property name="show_sql">true</property>

格式化sql代码:

<property name="format_sql">true</property>

自动提交代码:

<property name="connection.autocommit">true</property>

 

到此SSH2配置完成

注意要点:applicationContext.xml中配置actionpropertyname应所有为小写,

例如:

<bean id="ShopmessageAction" class="com.shop.action.ShopmessageAction">

       <property name="shopmessageinter">

           <ref bean="ShopmessageDAO" />

       </property>

    </bean>

DWR技术的整合

一、  在官网下载dwr.js文件,并下载相对应的common-logging-xxx.js

二、  解压dwr.js,找到相对应的engine.js  util.js

三、  在工程下webRoot下创建dwr文件夹, engine.jsutil.js放进去。

四、  WEB_INF下创建dwr.xml 文件

五、  web_inf下的lib文件夹下放进dwr.js common-logging-xxx.js

六、  web.xml中创建dwr.xml的相关文件信息

代码示例:

 

  <servlet>

<!—servlet name  -- > 

  <servlet-name>dwr-invoker</servlet-name>

<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>

 

    <!—调试模式为true自动生成的测试页-----This should NEVER be present in live -->

    <init-param>

      <param-name>debug</param-name>

      <param-value>true</param-value>

    </init-param>

 

    <!—是否容许翻转 Remove this unless you want to use active reverse ajax -->

    <init-param>

      <param-name>activeReverseAjaxEnabled</param-name>

      <param-value>true</param-value>

    </init-param>

 

    <!-- By default DWR creates application scope objects when they are first

    used. This creates them when the app-server is started -->

    <init-param>

      <param-name>initApplicationScopeCreatorsAtStartup</param-name>

      <param-value>true</param-value>

    </init-param>

   

    <init-param>  

            <param-name>crossDomainSessionSecurity</param-name>  

            <param-value>false</param-value>  

      </init-param>

 

    <!-- This enables full streaming mode. It's probably better to leave this

    out if you are running across the internet -->

    <init-param>

      <param-name>maxWaitAfterWrite</param-name>

      <param-value>-1</param-value>

    </init-param>

 

    <!--

    For more information on these parameters, see:

    - http://getahead.org/dwr/server/servlet

    - http://getahead.org/dwr/reverse-ajax/configuration

    -->

<--标记容器是否在启动的时候就加载这个servlet -- >

    <load-on-startup>0</load-on-startup>

  </servlet>

 

  <servlet-mapping>

    <servlet-name>dwr-invoker</servlet-name>

    <url-pattern>/dwr/*</url-pattern>

  </servlet-mapping>

 

七、  dwr.xml 中配置要调用的js函数,bean路径

代码示例:

<allow>

       <create creator="spring" javascript="role">

           <param name="beanName" value="RoleDAO" />

        

       </create>

 

       <convert converter="bean" match="com.shop.entity.Role" />

       <convert converter="exception" match="java.lang.Exception"/>

       <convert converter="bean" match="java.lang.StackTraceElement" />

</allow>

八、 错误解析

Java.lang.numberformat:null:

web.xml 中忘记配置:

<load-on-startup>0</load-on-startup>

        HTTP Status 501 - Error. Details logged to the console    Session error :

在配置信息中忘记配置:

<init-param>  

            <param-name>crossDomainSessionSecurity</param-name>  

            <param-value>false</param-value>  

      </init-param>

 

标签库的导入

         引入标签库两种方法:

         jsp标签中添加

例如引如struts标签: <%@ taglib uri=”struts-tags” prefix=”s”>

         web.xml 中配置以下

例如:<jsp-config>

    <taglib>

       <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>

       <taglib-location>/WEB-INF/tld/c.tld</taglib-location>

    </taglib>

</jsp-config>

 

引入标签:

Struts:<%@ taglib uri=”struts-tags” prefix=”s”>

Jstl: <%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c”>

 【引入jstl标签需在lib 文件夹下放进jstl.jarstandard.jar ,web-Inf下创建tld文件夹,把解压的tld文件夹下的文件放进去,taglib-location须要此路径】