SSH框架搭建

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1、创建web应用

2、添加spring支持,选择需要的类库,并选择“JAR Libraries Installation”中第二个选项:Copy checked Library contents to project folder (TLDs always copied),将类库保存到项目的lib目录下。

3、添加Hibernate支持:

4、下一步:选择“Spring Configuration file(applicationContext.xml)“

5、下一步:选择“Existing Spring configuration file”在SessionFactory Id 中填入sessionFactory.

6、下一步:如图填写

7、添加Hibernate实体及其映射文件

8、对Dao类中的方法抽取接口并将接口和实现分包放置,

9、建立biz接口和bizImpl实现类,实现类中添加Dao接口的引用,并添加get/set方法,

10、在具体业务方法中调用Dao的方法实现业务逻辑。

11、在applicationContext.xml中配置bizImpl实现类

12、添加Struts支持,在struts-config.xml中添加插件元素:

className="org.springframework.web.struts.Context LoaderPlugIn">

13、创建form/Action/Jsp并将struts-config.xml文件中Action的type改为:type="org.springframework.web.struts.DelegatingAc tionProxy"

14、在Action中添加Biz接口的引用,并添加get/set 方法

15、编写要执行的Action方法,调用Biz引用完成业务操作。完成后转入到指定页面。

16、在applicationContext.xml中配置Action:将bean的id改为name=“path“

class="com.ssh.struts.action.AccountAction">

17、编写页面代码,加入方法参数

18、注意需要将库中的sam.2.2.3.jar删除,否则它和sam.jar

包冲突,会出现如下错误:

org.springframework.beans.factory.BeanCreationExc eption: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table goods refers to an unmapped class: er

19、配置事务(参见配置模板)

20、部署项目,运行项目。

21、可能的异常:

版本引发的异常:

org.springframework.beans.factory.BeanCreationExc eption: Error creating bean with name 'transactionManager' defined in file [D:\tools\Tomcat

6.0\webapps\umgoods\WEB-INF\classes\applicationCo ntext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationExc eption: Error creating bean with name 'sessionFactory' defined in file [D:\tools\Tomcat 6.0\webapps\umgoods\WEB-INF\classes\applicationCo ntext.xml]: Invocation of init method failed; nested exception is ng.UnsupportedClassVersionError: Bad version number in .class file (unable to load class er)

提示:因为MyEclipse7.0用的是5.0版本的JDK,而tomcat用

相关文档
最新文档