SSH+DWR 架構 整合

來源:互聯網
上載者:User

SSH 架構整合    口袋茶葉 製作整理


添加順序:Struts架構,Spring架構,Hibernate架構

首先匯入兩個jar包:commons-dbcp-1.2.2.jar
  ,  commons-pool-1.3.jar 


複製進lib檔案夾即可

刪除原來的一個jar包commons-dbcp.jar 避免新舊版本衝突

Web.xml 檔案配置(整合Spring):

<context-param>

     <param-name>contextConfigLocation</param-name>

     <param-value>/WEB-INF/classes/applicationContext.xml</param-value>

</context-param>

<listener>

      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

 

Struts-config.xml 檔案配置

(首先需要建立好action,actionForm,然後更改type屬性)

<action

   .......

   type="org.springframework.web.struts.DelegatingActionProxy"

  />

 

將Acition類和其他相關bean配置進spring的設定檔applicationContext.xml中:

action類

<bean name="/path"
class="action所在的包.類名"

   <property name="action類中的屬性名稱">

        <ref bean="這個屬性所屬的類的類名,這個類必須也在本spring設定檔中有bean的配置"/>

   </property>

</bean>

bean類(如業務類)

<bean id="名稱"
class="bean所在的包.類名"

   <property name="該bean中的屬性名稱(如實體類屬性)">

        <ref bean="這個屬性所屬的類的類名,這個類必須也在本spring設定檔中有bean的配置"/>

   </property>

</bean>

 

DWR 架構整合  口袋茶葉 製作整理


添加DWR的jar包dwr.jar

在 WEB-INF 下建立 dwr.xml 檔案

配置該 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 javascript="UserBiz" creator="spring
">
       <param name="beanName
" value="UserBiz"></param>
    </create>
    <convert converter="bean" match="com.entity.UserInfo"/>     轉換類型
  </allow>

</dwr>

 

在 web.xml 裡添加配置:





<servlet>
      <servlet-name>dwr</servlet-name>
      <servlet-class>
          org.directwebremoting.servlet.DwrServlet
      </servlet-class>
</servlet>
<servlet-mapping>
      <servlet-name>dwr</servlet-name>
      <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

註:

填寫紅字部分的值,表示交給Spring管理

     name="beanName
"    還可以填寫“class”

     value="UserBiz"  UserBiz表示applicationContext中bean中配置的id名稱

     javascript="UserBiz" 表示 在jsp頁面裡面 匯入的 UserBiz.js 檔案

 

jsp頁面中匯入 js 檔案:

 <script type="text/javascript" src="/MyJob/dwr/interface/UserBiz.js
"></script>
 <script type="text/javascript" src="/MyJob/dwr/util.js
"></script>
 <script type="text/javascript" src="/MyJob/dwr/engine.js
"></script>

 

<script type="text/javascript">
  function show()
  {
   UserBiz.findALL(showBook);
  }
  function showBook(str)
  {
   var myDiv=document.getElementById("userInfo");
   var s="";
   for(var i=0;i<str.length;i++)
   {
    var user=str[i];
    s+=user.name+"=="+user.password+"<br>";
   }
   myDiv.innerHTML=s;
  }
 </script>

 </head>

 <body >
 <input type="button" onclick="show()" value="顯示">
  <div id="userInfo"></div>
 </body>

註:

該例子為 在頁面中 顯示userinfo表中的資訊。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.