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須要此路徑】

相關文章
相關標籤/搜索