最近啊现在公司面试可能会有一些的上机题出现了,不过还好,不是很难,都是一些SSH配置然后做一个很简单的小功能啊什么的。那么这个大家平常的SSH都是怎么配的呢,如果让你上网还好,如果不让你上网是不是当时就蒙了呢。
其实不让你上网那我们就自己弄吧,没什么大不了的。熟悉一两次就好了,面试的时候千万不能让那些没有技术含量的东西给卡下来了,那可真就太不值得了。
如果只给你hibenrate包,spring包和struts包,那么让你将这三个框架配置起来做以
个登陆,那么你应该怎么去集成呢?这几个配置文件怎么去弄呢?
1.首先拷贝jar包,
a)那么struts中的jar包都需要拷贝什么呢?将struts中的所有的包都拷贝过来,一共是八个.然后就是jstl的包也要拷过来.所以struts的jar包一共是十个.
b)然后是hibernate包的拷贝.hibernate的拷贝比较简单,一个lib下面是38个,然后还有以个核心包hibernate3.jar,所以一共是39个jar包.
c)然后就是spring的配置了,spring比较麻烦一点点,它一共有四个,以个是核心包spring.jar,一个是lib/aspectj下面的两个jar包,以个是junit测试包lib/junit下的junit.jar.
d)最后就是mysql的包了,那么你用哪个数据库就自己往里面加哪个数据库的包吧.
2.当jar包拷贝完了之后呢我们开始写配置文件了,首先我们从底层来写这个配置文件,从hibernate.cfg.xml开始.这个文件我们可以从我们下的hibernate的jar包里面找到. 我们可以在hibernate-3.2.0/etc里面找到hibernate.cfg.xml这个文件,然后我们拷贝到我们的src中,然后我们删掉其中没有用的东西,只留下下面这些.
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
</session-factory>
</hibernate-configuration>
3.紧接着我们开始陪上一层的配置文件,这是以个spring的配置文件,这个spring的配置文件一共有三个,第一个就是applicationContext-common.xml,它是负责我们的事务的配置,我们要保持事务,那么就要用spring来给我们管理session,那么我们的sessionFactory就是由spring来创建的,而且在这个里面我们需要配置事务的传播特性,哪些方法要使用事务,事务的传播特性.这个xml文件前面的头部信息可以从另外一个文件(spring-framework-2.0/samples/jpetstore/war/WEB-INF)里面拷过来,这样这个头文件就有了,注意其他的applicationContext拷贝过来它的头部信息可能会少一些,那么有可能影响我们的程序的运行,所以我们用这个里面的头文件.
4.然后我们还要准备以个applicationContext-bean.xml文件,这个文件里面我们要放一些我们的业务逻辑类的配置,因为我们所有的业务逻辑类的创建都是由spring替我们完成的,那么我们就应该将所有的xxxManager都放到这个spring里面来配置,那么这个文件里面放置的都是xxxManager的配置.
5.然后我们还要准备以个applicationContext-action.xml来放置struts的action的配置,也就是我们的path对应的处理类是要在这个里面去配置的.
6.这三个文件我们建立完成了我们开始建立struts-config.xml文件,这个文件里面我们只需要留下最外层的框架就可以了.而且这个文件我们直接可以从struts-1.2.9-bin/webapps/struts-blank/WEB-INF这个里面去找到,然后把中间所有的东西都删掉.剩下的就就像这样:
7.然后我们开始配置我们的web.xml文件,这个文件的配置是最麻烦的,因为我们要控制session的打开和关闭,我们用到了openSessionInView,这个文件可以先从这个地方拿到tomcat/server/webapps/admin/WEB-INF,然后我们把这个文件里面没有用的东西都给它拿掉,留下这些内容:
8.现在我们的配置文件写完了,我们的任务完成了.
9.值得注意的是现在的公司越来越倾向与让你用ssh框架来做一个小的登陆系统,那么这个时候我们就要迅速的不加思索的知道我们要干什么,我们应该怎么去做,不要再在那想上一回,然后再去做,这个东西要相当相当的熟了才行啊.
10.在这个里面我们主要就是要记住spring的jar包都要加入哪些,然后我们要知道这个事务管理怎么去配置,然后我们要知道这些文件都要在哪个里面去拷贝.