SSH框架搭建
搭建环境:MyEclipse5.5 Sqlserver2005
第一步:在MyEclipse中创建一个WebProject工程,(ssh_project)
第二步:点击工程添加Struts支持,MyEclipse>>Add Struts Capabilities;(如图struts.png)
第三步:点击工程添加Spring支持,MyEclipst>>Add Spring Capabilities;(如图spring.png)
勾选Spring2>>勾选Spring2.0ORM/DAO.........>>勾选Spring2.0 J2EE...>>勾选web Libraries
JAR 勾选copy..... 完成
第四步:添加数据库连接 (DBBrowser 连接到Sqlserver2005数据库)(如图db.png)
第五步:点击工程添加Hibernate支持,MyEclipse>> Add Strust Capabilties;(如图hibernate1.2.3.4.png)
第六步:点击DB Browser 映射数据库表到Dao中(db2.png)
到这为止,基本搭建完毕然后要对搭建的框架修改
首先:删除多余,重复的jar 包(asm c3p0 cglb ) 添加 pool包
其次:
(1) 在Struts配置文件中配置插件,在struts-config.xml中加入:
<<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans >
……
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="userForm" name="userForm" parameter="op" path="/user" scope="request"
//关键地方
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="show" path="/show.jsp"></forward>
<forward name="error" path="/error.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.y2t22_1_hr.struts.ApplicationResources" />
//关键关键地方
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="classpath:applicationContext.xml"/>
</plug-in>
</struts-config>
最后:
在Sping配置文件中applicationContext.xml <bean>要用name属性 name要与Sttuts的action中的path属性一致+
<bean name=” /user” …..>