SSH 框架为 Struts + Spring + Hibernate。

      集成SSH框架的系统从职责上分为四层:数据持久层和域模块层,以帮助开发人员在短期内搭建结构清晰、可复用性好、维护方便的Web应用程序。其中使用Struts作为系统的整体基础架构,负责MVC的分离,在Struts框架的模型部分,控制业务跳转,利用Hibernate框架对持久层提供支持,Spring做管理,管理struts和hibernate。具体做法是:用面向对象的分析方法根据需求提出一些模型,将这些模型实现为基本的Java对象,然后编写基本的DAO(Data Access Objects)接口,并给出Hibernate的DAO实现,采用Hibernate架构实现的DAO类来实现Java类与数据库之间的转换和访问,最后由Spring做管理,管理struts和hibernate。



一、Struts 

  1)本质:过滤器(就像一条看门狗,一旦有请求访问就要经过它)

  2)功能:对用户发送的请求,按照不同的业务要求,跳转到不同的页面,把部分信息作为参数传递

二、Spring 

      1)本质:监听器(就像一只鸟,盘旋在空中,监视着程序运行,在程序运行过程中负责注入实例)     

  2)功能:管理所用到的实现类。

三、Hibernate

  1)本质:服务器和数据库交互的媒介

  2)功能:负责对数据库的一些操作(如:建表、增、删、查、改等)



大概结构,根据个人习惯


ssh框架编写rest接口 ssh框架实例_SSH



web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name></display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>
  	org.springframework.web.context.ContextLoaderListener
  </listener-class>
  </listener>
  <filter>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <filter-class>
        org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
  </filter>
  <filter-mapping>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <url-pattern>*.action</url-pattern>
  </filter-mapping>
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
	  		org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
	  	</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>
  <filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>
			cn.filter.CharacterEncodingFilter
		</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>






一,配置applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
	<!-- 加载Hibernate配置 -->
	<!-- <bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation">
			<value>classpath:hibernate.cfg.xml</value>
		</property>
	</bean> -->
	<!-- 定义dbcp数据源 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<!-- 指定JDBC驱动类 -->
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver">
		</property>
		<!-- 提供连接数据库的URL地址 -->
		<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl">
		</property>
		<!-- 提供连接数据库的用户名和密码 -->
		<property name="username" value="scott"></property>
		<property name="password" value="123456"></property>
	</bean>
	<!-- 定义SessionFactory Bean -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<!-- 为LocalSessionFactoryBean(AnnotationSessionFactoryBean)注入定义好的数据源 -->
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<!-- 添加Hibernate配置参数 -->
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.OracleDialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">true</prop>
			</props>
		</property>
		
		<!-- 添加对象关系映射文件 -->
		
		<property name="mappingDirectoryLocations">
			<list>
				<value>classpath:cn/entity</value>
			</list>
		</property>
	</bean>
	
	<!-- 配置DAO -->
	<bean id="GoodsDao" class="cn.dao.impl.GoodsDaoImpl">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<!-- 配置业务层 -->
	<bean id="GoodsBiz" class="cn.service.impl.GoodsBizImpl">
		<property name="goodsdao" ref="GoodsDao"></property>
	</bean>

	
	<!-- 定义事务管理器 -->
	<bean id="txManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	<tx:advice id="txAdvice" transaction-manager="txManager">
		<!-- 定义事务属性,声明事务规则 -->
		<tx:attributes>
			<tx:method name="find*" read-only="true" />
			<tx:method name="search*" read-only="true" />
			<tx:method name="query*" read-only="true" />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="register" propagation="REQUIRED" />
			<tx:method name="del*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="do*" propagation="REQUIRED" />
			<tx:method name="*" propagation="REQUIRED" read-only="true" />
		</tx:attributes>
	</tx:advice>
	<aop:config>
		<!-- 定义切入点 -->
		<aop:pointcut id="serviceMethod"
			expression="execution(* cn.service.impl.*.*(..))" />
		<!-- 将事务通知与切入点组合 -->
		<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
	</aop:config>

	<!-- 控制层 (id为struts.xml中的class) 以下每个bean必须都要增加scope="prototype"属性 -->
  	<bean id="GoodsAction" class="cn.action.GoodsAction" 
		scope="prototype">
		<property name="goodsbiz" ref="GoodsBiz"></property>
	</bean> 
	<bean id="updateAction" class="cn.action.updateAction" 
		scope="prototype">
		<property name="goodsbiz" ref="GoodsBiz"></property>
	</bean> 

</beans>

二,struts

<?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.enable.DynamicMethodInvocation" value="true" />
	<constant name="struts.custom.i18n.resources" value="message" />
	<constant name="struts.i18n.encoding" value="UTF-8" />
	<constant name="struts.ui.theme" value="simple" />
	<package name="renthouse" extends="struts-default">
		<default-action-ref name="defaultAction" />
		<action name="defaultAction" class="cn.action.Default">
			<result name="fail">/page/fail.jsp</result>
		</action>

		<action name="list" class="GoodsAction" method="list">
			<result name="success">/page/show.jsp</result>
		</action>


		<action name="updatelist" class="updateAction" method="list">
			<result name="success">/page/update.jsp</result>
		</action>
		<action name="update" class="updateAction" method="update">
			<!-- 进行重定向 -->
			<result name="success" type="redirectAction">list</result>
			<!-- 失败继续留在修改页面 -->
			<result name="input">/page/update.jsp</result>
		</action>
	</package>
</struts>

三,show.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'select.jsp' starting page</title>



</head>

<body>
	<s:form>
		<table border="1" align="center">
			<tr>
				<td>商品编号</td>
				<td>商品名称</td>
				<td>商品价格</td>
				<td>库存数量</td>
				<td>订单状态</td>
				<td>操作</td>
			</tr>
			<!-- cn.action.GoodsAction中的list() != null -->
			<s:if test="list!=null">
				<s:iterator value="list">
					<tr>
						<td><s:property value="id" />
						</td>
						<td><s:property value="goods_name" />
						</td>
						<td><s:property value="goods_price" />
						</td>
						<td><s:property value="goods_count" />
						</td>
						<td><s:property value="bill_status" />
						</td>
						<td>
							<a href="updatelist.action?id=<s:property value="id" />">修改</a>
						</td>
					</tr>
				</s:iterator>
			</s:if>
		</table>
	</s:form>


</body>
</html>

四  update.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'update.jsp' starting page</title>

</head>

<body>
	<s:form action="update.action">
		<s:iterator value="list">
			<table border="1" align="center">
				<tr>
					<td>商品编号</td>
					<td><s:textfield name="id" readonly="true" />
					</td>
				</tr>
				<tr>
					<td>商品名称</td>
					<td><s:textfield name="goods_name" />
					</td>
				</tr>
				<tr>
					<td>商品价格</td>
					<td><s:textfield name="goods_price" />
					</td>
				</tr>
				<tr>
					<td>库存数量</td>
					<td><s:textfield name="goods_count" />
					</td>
				</tr>
				<tr>
					<td>订单状态</td>
					<td><s:select name="bill_status"
							list="#{0:'待处理',1:'处理中',2:'已处理'}" headerKey="bill_status" />
					</td>
				</tr>
				<tr>

					<td colspan="2" align="center"><s:submit value="提交" /> <input
						type="button" value="返回" οnclick="window.history.go(-1)" />
					</td>
				</tr>
			</table>
		</s:iterator>
	</s:form>
</body>
</html>


五,index页面


<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
</head>

<body>
	<center>
		<s:form action="list.action">
    	请选择区域:<select class="text" name="goods_district">
    			<option value="0">请选择</option>
				<option value="1">朝阳区订单</option>
				<option value="2">海淀区订单</option>
				<option value="3">丰台区订单</option>
				<option value="4">西城区订单</option>
				<option value="5">昌平区订单</option>
			</select>
			<s:submit value="查询" />
		</s:form>

	</center>
</body>
</html>


实体类和*.hbm.xml根据逆向生成吧

具体自己百度

只是总结简单的环境搭建

写的不是很好,自己根据自己个人情况随便总结的

不喜勿喷