Myeclipse 創建ssh框架

1、new一個web project。

image

2、右鍵項目,爲項目添加Struts支持。

image

image

image

點擊Finish。src目錄下多了struts.xml配置文件。

image

3、使用MyEclipse DataBase Explorer建立數據源。

image

new一個數據源。填入數據源信息。

image

點擊test Driver,如果成功顯示:

image

點擊OK,點擊Finish。

4、爲項目添加Spring支持。

image

選擇五個包,之後JAR Library Installation爲如下圖。

image

點擊Next。

image

默認點擊Finish。

5、爲項目添加Hibernate支持。

image

image

默認的包,更改JAR Library Installation。

點擊Next。

image

選擇是建立Hibernate自己的配置文件,還是合併到Spring的配置文件。選擇合併,即更改點選框,點擊Next。

image

選擇Existing Spring Configration File,點擊Next。

image

選擇我們剛剛創建的數據源。點擊Next。

image

去掉複選框的勾勾,點擊Finish。

6、發佈項目,此時已經可以訪問這個項目的jsp頁面了。

image

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章