IDE: Eclipse Mars Release (4.5.0)
DB: MySQL 5.1.73
服務器: Tomcat 7.0
1,首先在Eclipse中新建一個Dynamic Web Project,暫且起名為SSH;
2,新建包名:
3,導入jar包:
4,配置Struts2框架:
a,在 web.xml 中配置struts2過濾器:
<filter>
<filter-name>action/<filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter/<filter-class>
<filter-mapping>
<filter-name>action/<filter-name>
<url-pattern>/*/<url-pattern>
b,新建config源文件夾,並在該文件夾中新建struts.xml配置文件
<struts>
<packagename>
5,將 log4j.properties 文件複製粘貼到 config 文件夾中;
6,新建 jdbc.properties 文件在 config 文件夾中:
7,新建 hibernate.cfg.xml 文件到 config 文件夾;
/p>
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<propertyname>org.hibernate.dialect.MySQL5Dialect/<propertyname>
<propertyname>update/<propertyname>
<propertyname>true/<propertyname>
8,新建 ApplicationContext.xml 文件在 config 文件夾中;
<beansxmlns>
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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<component-scanbase-package>
<property-placeholderlocation>
<beanid>
<propertyname>
<propertyname>
<propertyname>
<propertyname>
<propertyname>
<propertyname>
<propertyname>
<propertyname>
<beanid>
<propertyname>
<propertyname>
<propertyname>
<list>
<value>classpath:com/juyuan238/ssh/domin/<value>
<beanid>
<propertyname>
<adviceid>
<attributes>
<methodname>
<methodname>
<methodname>
<methodname>
<methodname>
<methodname>
<methodname>
<methodname>
<methodname>
<config>
<advisoradvice-ref>
9,配置 Spring 的監聽器在 web.xml 中;
10,新建測試類,測試數據源:
注: 如果正常的話,控制檯會打印出信息如下:
11,接下來的話,我們再來測試下發布成 web 應用時,框架是否能正確運行:
a,在 com.juyuan238.ssh.web 中新建一個類,暫且起名為: ShwAction
@Controller("shwAction")
publicclass ShwAction {
public String index(){
return"load";
}
}
b,到 struts2 配置文件 struts.xml 中,編寫配置文件:
<struts>
<packagename>
<actionname>
<resultname>WEB-INF/jsp/success.jsp/<resultname>
c,在WEB-INF 目錄下新建 jsp 文件夾,並在 jsp 文件夾中新建 success.jsp ;
注: 新建 jsp 頁面的時候,可能會發現 jsp 頁面報錯,沒事,這是正常的。解決辦法如下 :
右鍵當前項目---->Build Path---->Configure Build Path----->切換到" Libraries "------>Add Libray----->Server Runtime------->選擇相應的" Tomcat "版本---->finish----->OK
d,在 index.jsp 中添加超鏈接:
e,將項目部署到 tomcat 中,並啟動 tomcat 服務器;
f,點擊鏈接,如果能夠鏈接到 success.jsp 頁面,說明框架整合成功!否則的話,就要繼續努力了……
好了,三大框架的整合說到這裡就已經結束了,希望對大家能夠有所幫助……
歡迎大家在下方積極吐槽,小編會一一進行查看並回復,期待你的答案哦……
小熊原創,如果喜歡請轉發,小小支持一下。
/<beansxmlns>閱讀更多 小熊社長 的文章