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

 

平台:win7 myeclipse10 struts2  hibernate 3.3 spring3.0

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

ssh2的配置

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

Spring3.0:

         Spring 3.0 AOP Libraries

         Spring 3.0 Core Libraries

         Spring 3.0 Persistence Core Libraries

         Spring 3.0 Persistence  JDBC  Libraries

         Spring 3.0 Web Libraries

 

Hibernate 3.3:

         Hibernate  3.3  Annotations & Entity Manager

         Hibernate  3.3  Core Libraries

 

Struts2.1:

         Struts 2 Core Libraries

         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技术的整合

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

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

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

4、  WEB_INF下建立dwr.xml 文件

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

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

 

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

8、 错误解析

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需要此路径】

你可能感兴趣的:(Dwr技术与ssh2的相关配置技术摘要)