MyEclipse手動配置SSH框架

今天剛到公司開始第一天實習。要求用MyEclipse手動配置SSH 琢磨了半天,整理了下:

struts2配製:
1.導入:
commons-logging-1.0.4.jar
xwork-2.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.11.jar
struts2-spring-plugin-2.0.11.jar //不用spring不引入
2.改寫web.xml,在其中加入以下幾行
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3.在src下建立struts.xml,寫入:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts> 
<include file="struts-default.xml"/>
</struts>

4.添加spring框架
勾中前4個和spring2.0 web Liberarys
選中Cope to lib
5.添加hibernate框架
勾中前3個
選中copy to lib

6.調整包:
把MyEclipse創建spring2時候生成的commons-collections2.11刪除
另導入兩個jar包commons-collections.jar,commons-pool-1.4.jar
7.再次修改web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>

<!-- 下面也是spring2的配置 -->
  <listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
8.改寫struts.xml 加入:
是在後面的spring2配置中用到意思是把控制交給spring2
<constant name="struts.objectFactory" value="spring" /> 

9.在applicationContext.xml中加入
<bean id="hello" class="action.HelloAction">
</bean>
10.在struts.xml中改寫
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts> 
<constant name="struts.objectFactory" value="spring" />
<include file="struts-default.xml"/>
<package name="aa" extends="struts-default" namespace="/users">
<action name="hello" class="hello">
<result name ="ok" >/ok.jsp </result >
</action>
</package>

</struts>
 

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