我回來了!!從萬惡的D3煉獄中生病的痛苦中回來了
其實這次的教學沒有什麼東西~
就只是將原本的struts.xml拿掉~改成用註解的方式

討厭鬼 發表在 痞客邦 留言(0) 人氣()


照常理來說~這幾天討厭鬼應該是要發文的
可是~壓母溝,因為暗黑3的出現~
所以我忘記惹~所以現在趕快補一下

討厭鬼 發表在 痞客邦 留言(0) 人氣()

下載
這幾天看了有關紅茶淡定哥的相關文章
討厭鬼也想在coding的時候也能這麼的淡定呀
癈話好像太多了那就~

討厭鬼 發表在 痞客邦 留言(1) 人氣()


相信大家在寫頁面時明明都在jsp裡面設定了
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

討厭鬼 發表在 痞客邦 留言(0) 人氣()

images (9)
前幾天答應了人要發這篇文章
  
 

討厭鬼 發表在 痞客邦 留言(0) 人氣()

原本想要先發junit的~只是我突然想到
我還沒有配置transcation manager
為什麼要配置這個呢?
當然還是要來講一下例子

討厭鬼 發表在 痞客邦 留言(1) 人氣()

若還沒有看過前面幾篇文章的話建議先去看Struts2 架構配置教學、Struts2+Spring架構配置教學(Spring)、Struts2+Spring+Hibernate架構配置教學(Hibernate)上、Struts2+Spring+Hibernate架構配置教學(Hibernate+JNDI)下、Spring+Hibernate用法教學

討厭鬼 發表在 痞客邦 留言(8) 人氣()

daocontext
如果還沒有看過Struts2 架構配置教學、Struts2+Spring架構配置教學(Spring)、Struts2+Spring+Hibernate架構配置教學(Hibernate)上、Struts2+Spring+Hibernate架構配置教學(Hibernate+JNDI)下

討厭鬼 發表在 痞客邦 留言(9) 人氣()

SpringDAO1
若還沒看過這三篇的話~請先去看Struts2 架構配置教學、Struts2+Spring架構配置教學(Spring)、Struts2+Spring+Hibernate架構配置教學(Hibernate)上
雖然討厭鬼本身沒有很厲害

討厭鬼 發表在 痞客邦 留言(7) 人氣()

srcCfg
原本發完Spring那篇文章時~想說要再接再勵的發Hibernate的文章
但是我熊熊想到我的新筆電沒有灌資料庫呀~~~~~~~
所以這幾天在為資料庫所煩惱

討厭鬼 發表在 痞客邦 留言(5) 人氣()

討厭鬼在這跟大家說聲抱歉~本來是上禮拜要發文的


只是電腦去送修~才買15天~心裡是非常的


整個在挑戰我= =~還好取件時是個妹仔


頓時讓我心情好了一點


 


 


 


 


好吧~抱怨完了我們進入正題....吧


 


上次討厭鬼已經教了大家要如何配置Struts2


(若還沒有配置完Struts2的話請先看這篇Struts2 架構配置教學)


 


所以今天就以上次的教學為基礎再加上Spring


讓專案的架構變成Struts2 + Spring


癈話不多說~讓討厭鬼開始今天的配置教學吧


這次配置Spring所需要的jar為 
struts2-spring-plugin-2.2.3.jar
org.springframework.context-3.1.1.RELEASE.jar 
org.springframework.beans-3.1.1.RELEASE.jar 
org.springframework.core-3.1.1.RELEASE.jar 
org.springframework.web-3.1.1.RELEASE.jar 
org.springframework.asm-3.1.1.RELEASE.jar 
org.springframework.expression-3.1.1.RELEASE.jar 
commons-logging-1.1.1.jar


 


以上是配置Spring所必備的jar檔


 


接下來要配置web.xml


在web.xml中加入


    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>xxxxxxxxx.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


其中xxxxxxxxxx.xml是Spring設定檔的位置及名稱


若有多個時用逗點分開


如果沒有設定Spring的設定檔的話,那預設會抓applicationContext.xml


 


以下是我配置


 


spring 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"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <display-name>leather</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:nerdy/config/action-context.xml,
                    classpath:nerdy/config/service-context.xml,
                    classpath:nerdy/config/dao-context.xml
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <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>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>


 


接下來要設置Spring的設定檔


這邊要看各位客倌在web.xml中設定幾個,就要有幾個


因為討厭鬼在web.xml中設定了3個所以我要在


src底下的nerdy.config這個package底下加入action-context.xml,service-context.xml,dao-context.xml這三個檔案


在Spring的設定檔中的開頭加入


 


<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd ">
</beans>


 


若有用到多個設定檔,那開頭的設定應該是一樣的~~~~~~~


基本上在這個時候Spring已經算是架設完畢了


只是還算不上是 Struts2 + Spring 的架構


因為還沒有將Struts2納入Spring的控管之下


所以要再加入一行


 


<bean id="xxxxxx" class="xxxxx.xxxx"></bean>


 


id隨便取class是指要指定的class檔


以下是我的配置


 


spring context.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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd ">
    <bean id="indexAction" class="nerdy.action.IndexAction"></bean>
</beans>


 


接著再把Struts.xml打開


將原本action class的名稱 改成在Spring設定檔中的bean id的名稱


如範例本來是nerdy.action.IndexAction改為我剛剛在Spring設定檔中的bean id 的indexAction


 


spring struts


 


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
    "http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
    <package name="default" extends="struts-default">
        <action name="index" class="indexAction" method="index">
            <result name="success">/index/index.jsp</result>
        </action>
    </package>
</struts>
   


再將專案放到tomcat上執行,再鍵入網址 http://localhost:8080/leather/index.action


畫面跑出來了~建置成功


 


spring web


 


恭喜你~你已經學會了 Struts2+Spring了


 


基本上Spring的設定檔裡面的配置都差不多~端看個人怎麼設定


在這邊我是有關action的放在action-context.xml


有關service的放在service-context.xml


有關dao與資料庫的放在dao-context.xml


因為這邊只是先講建置架構~所以有關Spring的用法就沒有講了~


等到Hibernate建置完成


再開始說要如何去使用Spring的set跟annotation


 


 


 


 


補充


因為還沒有建置Hibernate所以資料庫連線的地方就先不講了


會在建置Hibernate的時候跟大家一起說明的


下次就要發表加入hibernate的重頭戲了



討厭鬼 發表在 痞客邦 留言(3) 人氣()

web.xml
最近常常在用SSH架構
也就是所謂的Struts2 + Spring + Hibernate
也常常找不到一些有用的資料
所以討厭鬼決定要來寫一個詳細的建置步驟     

討厭鬼 發表在 痞客邦 留言(21) 人氣()

1
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。