(二)搭建SSH环境

一、struts

1、添加jar

commons-fileupload-1.3.1.jar,【文件上传相关包】

commons-io-2.2.jar,

commons-lang-2.4.jar ,

commons-lang3-3.2.jar, 【struts对java.lang包的扩展】

freemarker-2.3.19.jar, 【struts的标签模板库jar文件】

ognl-3.0.6.jar,

struts2-core-2.x.jar,   【struts2核心功能包】

struts2-spring-plugin-2.x.jar,

xwork-core-2.x.jar      【Xwork核心包】

到web-inf/lib目录下。

2、添加struts.xml

到src目录下。可在“struts-2.xappsstruts2-blankWEB-INFclasses”下复制。

在struts.xml中添加几个常用属性:

1 <!-- 禁用动态方法访问 -->
2     <constant name="struts.enable.DynamicMethodInvocation" value="false" />
3     <!-- 配置成开发模式 -->
4     <constant name="struts.devMode" value="true" />
5     <!-- 配置拓展名为action -->
6     <constant name="struts.action.extention" value="action" />
7     <!-- 把主题配置成simple -->
8     <constant name="struts.ui.theme" value="simple" />

3、配置web.xml

     添加struts2 过滤器: 

1 <filter>
2         <filter-name>struts2</filter-name>    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
3     </filter>
4 
5     <filter-mapping>
6         <filter-name>struts2</filter-name>
7         <url-pattern>*.action</url-pattern>   
8     </filter-mapping>

二、Hibernate

添加hibernate jar

 hibernate3.jar,

lib/required/*.jar,

libjpahibernate-jpa-2.0-api-1.0.0.Final.jar,

libytecodecglibcglib-2.2.jar

到web-inf/lib目录下。

至于hibernate.cfg.xml文件,因项目使用spring来整合管理实体和数据库的连接等hibernate原本的工作,所以这个配置文件不再需要。

三、Spring

添加spring3.0.2中的jar

 

添加spring配置文件applicationContext.xml 到src目录下;

在web.xml中注册spring监听器,启动spring容器:

1 <listener>
2        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
3     </listener>
4     <context-param>
5         <param-name>contextConfigLocation</param-name>
6         <param-value>classpath:applicationContext.xml</param-value>
7     </context-param>
原文地址:https://www.cnblogs.com/Michael2397/p/5926061.html