力所能及之SSH环境搭建

小狼最近心血来潮,搭建了一个SSH环境,跟大家分享分享

开发环境:Windows7 ,jdk1.6  myeclispe8.6  tomcat6.0.18   mysql5.0

需要jar文件:

junit:junit.jar

db:mysql-connector-java-5.1.10-bin.jar

hibernate3.5.6:

jstl:                        

spring2.5.5:       

struts2:               

工程目录:

配置文件:

web.xml

 <listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>

	<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>
	</filter-mapping>

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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                           http://www.springframework.org/schema/aop
                           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context-2.5.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
       <import resource="applicationContext-db.xml"/>
       <import resource="applicationContext-user.xml"/>

</beans>

applicationContext-db.xml

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
     	<property name="configLocation">
     		<value>classpath:hibernate.cfg.xml</value>
     	</property>
     </bean> 

     <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
     	<property name="sessionFactory">
     		<ref bean="sessionFactory"/>
     	</property>
     </bean>
     <tx:advice transaction-manager="transactionManager" id="tx">
     	<tx:attributes>
     		<tx:method name="save*" read-only="false"/>
     		<tx:method name="update*" read-only="false"/>
     		<tx:method name="delete*" read-only="false"/>
     		<tx:method name="*" read-only="true"/>
     	</tx:attributes>
     </tx:advice>

     <aop:config>
     	<aop:pointcut expression="execution(* qh.zcy.service.*.*(..))" id="perform"/>
     	<aop:advisor advice-ref="tx" pointcut-ref="perform"/>
     </aop:config>   

applicationContext-user.xml

       <bean id="userDao" class="qh.zcy.dao.UserDao">
          <property name="sessionFactory" ref="sessionFactory"></property>
       </bean>
       <bean id="userService" class="qh.zcy.service.UserService">
          <property name="dao" ref="userDao"></property>
       </bean>
       <bean id="userAction" class="qh.zcy.action.UserAction" scope="prototype">
           <property name="service" ref="userService"></property>
       </bean>

hibernate.cfg.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
	<property name="hibernate.connection.driver_class">
		com.mysql.jdbc.Driver
	</property>
	<property name="hibernate.connection.url">
		jdbc:mysql://localhost:3306/zhang
	</property>
	<property name="hibernate.connection.username">root</property>
	<property name="hibernate.connection.password">root</property>
	<property name="hibernate.dialect">
		org.hibernate.dialect.MySQLDialect
	</property>

	<property name="hibernate.current_session_context_class">org.springframework.orm.hibernate3.SpringSessionContext</property>
	<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
	<property name="hibernate.hbm2ddl.auto">update</property>
	<property name="show_sql">true</property>
	<property name="format_sql">true</property>
	<mapping resource="qh/zcy/entity/User.hbm.xml" />

</session-factory>
</hibernate-configuration>

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
	"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
   <!-- 配置文件改了以后不用重新启动 -->
   <constant name="struts.devMode" value="true"/>

   <package name="SSH" extends="struts-default" namespace="/">
         <action name="userAction_*" class="userAction" method="{1}User"></action>

   </package>
</struts>	

UserAction.jave

package qh.zcy.action;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.opensymphony.xwork2.ActionSupport;

import qh.zcy.entity.User;
import qh.zcy.service.UserService;

@Transactional(propagation=Propagation.REQUIRED)
public class UserAction extends ActionSupport{

	private UserService service;

	public UserService getService() {
		return service;
	}

	public void setService(UserService service) {
		this.service = service;
	}

	public String listUser() throws Exception {
		// TODO Auto-generated method stub
		System.out.println(service.getUsers());
		return null;
	}
	public String saveUser() throws Exception {
		// TODO Auto-generated method stub
		User user=new User();
		user.setPassword("zhang");
		user.setUsername("zhang");
		service.saveUser(user);
		return null;
	}

}

至此SSH环境搭建完毕,测试一下:

http://localhost:8080/SSH/userAction_save.action

控制台输出如下:

时间: 2024-08-24 13:48:34

力所能及之SSH环境搭建的相关文章

Linux下的ssh环境搭建与管理

Linux下的ssh环境搭建与管理 实验环境 1:网桥模式 2:安装好vmtoos 3:安装好yum 4:安装好ssh相关软件包 5:服务端:xuegod-63   IP:192.168.1.63 客户端:xuegod-64   IP:192.168.1.64 客户端普通用户:ceshi  密码:123456 6:安装好扫描软件rpm -ivh/mnt/Packages/nmap-5.21-4.el6.x86_64.rpm 实验目标 1:SSHD服务介绍 2:SSHD服务安装配置 3:两Linu

ssh环境搭建与管理(详解)

ssh环境搭建与管理 (详解) 实验环境 服务端:xuegod-63   IP:192.168.1.63 客户端:xuegod-64   IP:192.168.1.64 客户端普通用户:ceshi  密码:123456 安装好扫描软件rpm -ivh /mnt/Packages/nmap-5.21-4.el6.x86_64.rpm 实验目标 1:SSHD服务介绍 2:SSHD服务安装配置 3:两Linux服务器之间数据拷贝 4:SSHD服务作用: 实验步骤 1:搭建环境 1):网桥模式 2):v

SSH环境搭建步骤

SSH环境搭建 springmvc 环境基本配置 引入jar>>web-inf/lib 1:配置web.xml 中 前端控制器,初始化配置 2:创建springmvc 的xml文件 2.1 扫描包 2.2 跳转文件的前后缀 ------------------------------------------------------------------------------------- spring 环境基本配置 引入jar>>web-inf/lib 1:在web.xml 中

力所能及之springmvc环境搭建

小狼从12年学习java开始,就听老师说了若干springmvc的高大上,可是人家就吊你胃口,死活不给你讲.当然,小狼不是盈利机构,不需要赶时间,这个该讲,那个不该讲的.今天,小狼就说说springmvc的环境搭建. 开发环境:myeclipse8.6  spring4.0 开发需要的jar文件: 项目结构: web.xml配置: <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu

SSH环境搭建

SSH为 struts+spring+hibernate的一个集成框架,是目前较流行的一种Web应用程序开源框架.集成SSH框架的系统从职责上分为三层:表示层.业务逻辑层和数据持久层,以帮助开发人员在短期内搭建结构清晰.可复用性好.维护方便的Web应用程序.其中使用Struts作为系统的整体基础架构,负责MVC的分离,在Struts框架的模型部分,控制业务跳转:利用Hibernate框架对持久层提供支持,处理请求数据并返回结果:Spring则是做管理,管理struts和Hibernate. 不管

SSH环境搭建,配置整合初步(一)

1,新Web工程,并把编码设为utf-8(所有的都是uft8数据库也是,就不会乱码了) 2,添加框架环境 Junit Struts2 Hibernate Spring 3,整合SSH Struts2与Spring整合 Hibernate与Spring整合 4,资源分类 5,配置日志 Struts2 jar包 struts.xml, web.xml Hibernate jar包:核心包, 必须包, jpa, c3p0, jdbc hibernate.cfg.xml, *.hbm.xml Sprin

GateOne Web SSH 环境搭建

环境配置安装python及tornadoyum -y install python-pippip install tornado GateOne安装下载源码:git clone https://github.com/liftoff/GateOne.git安装:cd GateOnepython setup.py install --prefix=/usr/local/ 配置vim /etc/gateone/conf.d/10server.conf// 默认false, 修改为true, 关闭htt

spring环境搭建

在做ssh环境搭建时,先搭建spring和hibernate的环境搭建,在搭建struts环境. 好处:在搭建struts环境之前出的错和web容器无关. 一.引入配置文件 1:从已有的配置文件复制过来 2:通过xml模板新建配置文件: a:首先进行applicationContext.xml文件提示配置(下次再配置可省略此步骤): Window----preferences----输入xml----选择xml Catalog----add配置 b:右键new---XML(Basic Templ

SSH框架总结(框架分析+环境搭建+实例源代码下载)

首先,SSH不是一个框架,而是多个框架(struts+spring+hibernate)的集成,是眼下较流行的一种Web应用程序开源集成框架,用于构建灵活.易于扩展的多层Web应用程序. 集成SSH框架的系统从职责上分为四层:表示层.业务逻辑层.数据持久层和域模块层(实体层). Struts作为系统的总体基础架构,负责MVC的分离,在Struts框架的模型部分,控制业务跳转,利用Hibernate框架对持久层提供支持.Spring一方面作为一个轻量级的IoC容器,负责查找.定位.创建和管理对象及