1、new一個web project。
2、右鍵項目,爲項目添加Struts支持。
點擊Finish。src目錄下多了struts.xml配置文件。
3、使用MyEclipse DataBase Explorer建立數據源。
new一個數據源。填入數據源信息。
點擊test Driver,如果成功顯示:
點擊OK,點擊Finish。
4、爲項目添加Spring支持。
選擇五個包,之後JAR Library Installation爲如下圖。
點擊Next。
默認點擊Finish。
5、爲項目添加Hibernate支持。
默認的包,更改JAR Library Installation。
點擊Next。
選擇是建立Hibernate自己的配置文件,還是合併到Spring的配置文件。選擇合併,即更改點選框,點擊Next。
選擇Existing Spring Configration File,點擊Next。
選擇我們剛剛創建的數據源。點擊Next。
去掉複選框的勾勾,點擊Finish。
6、發佈項目,此時已經可以訪問這個項目的jsp頁面了。
7、後續工作。
在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>在applicationContext中的bean爲sessionFactory添加屬性
<!-- 設置控制檯輸出sql語句最大輸出數爲50 -->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>在struts.xml中添加
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.custom.i18n.resources" value="cn.s2sh.action.token"></constant>
<constant name="struts.objectFactory" value="spring" />還要記得添加好struts2-spring-plugin-2.1.8.1.jar包這是要自己加到lib的
出去struts2自帶的包antlr-2.7.2ss.jar