ssh的原理和流程
一、strtus:第1步:把上面的jar包下载完成后,先在eclipse中新建一个web工程,新建工程的同时最好选上创建的同时添加web.xml文件
第2步:找到下载并解压好的strtus文件中找到apps目录下的strtus2-blank.war的压缩包,再找到这个压缩包中WEB-INF目录下的lib目录,最后将lib中的所有jar包复制到我们新建项目的lib包中
第3步:配置web.xml文件,找到前面lib包所在的同级目录下的web.xml文件,复制出其配置的过滤器,
注意:由于struts版本不同所以其配置的过滤器写法上略有差异,我们一般参照官方给的模板
第4步:我们可以写我们的action类了,编写action类我们一般会继承ActionSupport父类在aciton类中我们可以定义一个返回值为String类型的execute()方法[该方法为默认方法]。这里的action我们可以简单理解为MVC模式下的控制器
第5步:我们需要配置一个非常重要的struts.xml文件,我们还是找到前面lib包所在同级目录下的src目录下的java目录下的struts.xml文件将xml文件头信息复制出来
第6步:运行项目

此时我们发现我们的请求已经被struts成功拦截,接下来我们输入我们正确的访问路径也就是我们上一步配置action中name属性的值

如图所示页面已经正常显示,最后我们看一下后台

二、Spring
简介:从简单性、可测试性和松耦合的角度而言,任何java应用都可以从Spring中受益。简单来说,Sring就是一个轻量级的控制反转(IoC)和页面切向(AOP)容器框架。
1)本质:监听器(就像一只鹰,盘旋在空中,监视着程序运行,在程序运行过程中负责注入实例)
2)功能:管理所用到的实现类。
3)在 eclipse 中使用 Spring4(配置好 Struts 的基础上):
①、导入相应的 jar 包( spring 官方包里,lib 目录里除了带 resource 和 javadoc 后缀的jar包):

②、配置 web.xml 文件添加 Listener

<!-- spring的监听器配置开始 -->
<!-- 配置上下文参数,保存 applicationContext.xml 文件的路径,该文件一般直接写在 src 目录下 -->
<context-param>
<!-- 参数名称(固定不变) -->
<param-name>contextConfigLocation</param-name>
<!-- classpath(既 src 目录)":"等价于"/",多个配置文件之间用","隔开 -->
<param-value>classpath:applicationContext.xml,classpath:xxx.xml,……</param-value>
</context-param>
<!-- 监听器配置 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">
<!-- 类似于财务部门一样,类就是钱,所有需要类的实例都由srping去管理 -->
<!-- 给 Struts 注入相应的实现类 -->
<bean id="myIndexAction" class="ssh.action.IndexAction" scope="prototype">
<!-- 等价于 setIs(myIndexService),实现注入 -->
<property name="is" ref="myIndexService"/>
</bean> <!-- 等价于myIndexService = new ssh.service.IndexServiceImpl() -->
<bean id="myIndexService" class="ssh.service.IndexServiceImpl" scope="prototype">
<property name="id" ref="myIndexDao"/>
</bean>
<!-- 同上 -->
<bean id="myIndexDao" class="ssh.dao.IndexDaoImpl" scope="prototype">
<!-- 加入 hibernate 的配置信息,这里先不用管 -->
<property name="sf" ref="sessionFactory"></property>
</bean>
</beans>

Hibernate工作原理及为什么要用?
原理:
1.通过Configuration().configure();读取并解析hibernate.cfg.xml配置文件
2.由hibernate.cfg.xml中的<mapping resource="com/xx/User.hbm.xml"/>读取并解析映射信息
3.通过config.buildSessionFactory();//创建SessionFactory
4.sessionFactory.openSession();//打开Sesssion
5.session.beginTransaction();//创建事务Transation
6.persistent operate持久化操作
7.session.getTransaction().commit();//提交事务
8.关闭Session
9.关闭SesstionFactory
第1步:我们依旧需要引入hibernate的jar包
找到hibernate解压好的文件目录,在该目录下的lib目录下有一个required目录,将该目录下的所有jar包引入到我们项目的lib目录下。

第2步:我们又要和配置文件打交道了,首先我们要配置一个在src目录下的一个实体映射文件entityname.hbm.xml。

1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE hibernate-mapping PUBLIC
3 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
4 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
5 <hibernate-mapping>
6 <class name="entity.BookCard" table="BookCard">
7 <id name="cid" column="cid"></id>
8 <property name="name" column="name" type="string" length="50" not-null="true"></property>
9 <property name="sex" column="sex"></property>
10 <property name="cardDate" column="cardDate"></property>
11 <property name="deposit" column="deposit"></property>
12 </class>
13 </hibernate-mapping>

1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE hibernate-configuration PUBLIC
3 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
4 "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
5
6 <hibernate-configuration>
7 <session-factory name="foo">
8 <!-- 配置mySql连接参数 -->
9 <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
10 <property name="connection.pool_size">5</property>
11 <property name="show_sql">true</property>
12 <property name="format_sql">true</property>
13 <property name="hbm2ddl.auto">update</property>
14
15 <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
16 <property name="connection.url">jdbc:mysql://localhost:3306/CardDB</property>
17 <property name="connection.username">root</property>
18 <property name="connection.password">123456</property>
19
20 <mapping resource="BookCard.hbm.xml"/>
21 </session-factory>
22
23 </hibernate-configuration>

页面中的数据已经成功显示

ssh的原理和流程的更多相关文章
- ssh登录原理及免密登录配置
ssh登录原理参考: https://www.cnblogs.com/hukey/p/6248468.html ssh登录有两种方式: 1):用户名密码登录 2):基于秘钥的登录 ssh免密登录指的就 ...
- Linux可插拔认证模块(PAM)的配置文件、工作原理与流程
PAM的配置文件: 我们注意到,配置文件也放在了在应用接口层中,他与PAM API配合使用,从而达到了在应用中灵活插入所需鉴别模块的目的.他的作用主要是为应用选定具体的鉴别模块,模块间的组合以及规定模 ...
- Web程序的运行原理及流程(一)
自己做Web程序的开发也有两年多了 从最开始跟风学框架 到第一用上框架的欣喜若狂 我相信每个程序员都是这样过来的 在大学学习一门语言 学会后往往很想做一个实际的项目出来 我当时第一次做WEB项目看 ...
- paip.提升效率--数据绑定到table原理和流程Angular js jquery实现
paip.提升效率--数据绑定到table原理和流程Angular js jquery实现 html #--keyword 1 #---原理和流程 1 #----jq实现的代码 1 #-----An ...
- MySQL复制表的方式以及原理和流程
复制表的俩种方式: 第一.只复制表结构到新表 create table 新表 select * from 旧表 where 1=2 或者 create table 新表 like 旧表 第二.复制表结 ...
- Java 详解 JVM 工作原理和流程
Java 详解 JVM 工作原理和流程 作为一名Java使用者,掌握JVM的体系结构也是必须的.说起Java,人们首先想到的是Java编程语言,然而事实上,Java是一种技术,它由四方面组成:Java ...
- SSH加密原理、RSA非对称加密算法学习与理解
首先声明一下,这里所说的SSH,并不是Java传统的三大框架,而是一种建立在应用层和传输层基础上的安全外壳协议,熟悉Linux的朋友经常使 用到一 个SSH Secure Shell Cilent的工 ...
- FastDFS tracker storage 的工作原理及流程
FastDFS tracker storage 的工作原理及流程 2013 年 3 月 11 日 – 09:22 | 1,409 views | 收藏 (No Ratings Yet) FastDF ...
- ARKit从入门到精通(2)-ARKit工作原理及流程介绍
转载:http://blog.csdn.net/u013263917/article/details/73038519 1.1-写在前面的话 1.2-ARKit与SceneKit的关系 1.3-ARK ...
随机推荐
- Effective C++ 33 避免遮掩继承而来的名称
首先介绍一个原则LSP(Liskov Substitution Principle),如果Class D以Public方式继承Class B,则所有B对象可以派上用场的任何地方,D对象一样可以派上用场 ...
- SQL/T-SQL实例参考
,D.[Score] B_Score ,'Distince'= CASE WHEN C.Score > D.Score THEN C.[Score] - D.[Score] WHEN C.Sco ...
- Magento 新增字段的值读写丢失原因
某实体新增字段handreturn_status,欲操作之: $order_info = Mage::getModel('sales/order')->load($order_id); //se ...
- Quartz Job基本示例
项目中用到job的主要是各种公告,比如活动开始公告这种,以此为例: public class Domain { public Domain() { AnnounceManager.getIns().s ...
- MySQL批量UPDATE多行记录
UPDATE categories SET display_order = CASE id WHEN 1 THEN 3 WHEN 2 THEN 4 ...
- Linux-终端-快捷键
Linux-终端-快捷键 Shift+Ctrl+T:新建标签页 Shift+Ctrl+W:关闭标签页 Ctrl+PageUp:前一标签页 Ctrl+PageDown:后一标签页 Shift+Ctrl+ ...
- FileReader:读取本地图片文件并显示
最近忙得比狗还惨,导致长时间没能更新文章,真心对不住啊.抽空整理了下关于在页面上读取和显示本地图片的实例文章,本文通过实例讲解如何使用支持FileReader浏览器的用户将能够通过一个file inp ...
- Jprofile监控本地tomact
第一步:安装Jprofile后,点击jprofiler.exe 第二步:配置要监控的tomact 1.点击startcenter 2.弹出对话框,点击new session下面的new server ...
- 哈,我自己翻译的小书,马上就完成了,是讲用python处理大数据框架hadoop,spark的
花了一些时间, 但感觉很值得. Big Data, MapReduce, Hadoop, and Spark with Python Master Big Data Analytics and Dat ...
- SQL Server 2012 新增语法
--连接两个字符串. CONCAT(TelePhone,UserName,' : ',LoginVCode) FROM [dbo].[TB_NUsers] --SQL Server2012新增了两个逻 ...