博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SSH标准配置
阅读量:4052 次
发布时间:2019-05-25

本文共 5896 字,大约阅读时间需要 19 分钟。

SSH标准配置

 

最近啊现在公司面试可能会有一些的上机题出现了,不过还好,不是很难,都是一些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中,然后我们删掉其中没有用的东西,只留下下面这些.

Java代码
  1.     <!DOCTYPE hibernate-configuration PUBLIC   
  2.     "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
  3.     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">   
  4.   
  5. <hibernate-configuration>   
  6.     <session-factory>   
  7.            
  8.     </session-factory>   
  9. </hibernate-configuration>  

     3.紧接着我们开始陪上一层的配置文件,这是以个spring的配置文件,这个spring的配置文件一共有三个,第一个就是applicationContext-common.xml,它是负责我们的事务的配置,我们要保持事务,那么就要用spring来给我们管理session,那么我们的sessionFactory就是由spring来创建的,而且在这个里面我们需要配置事务的传播特性,哪些方法要使用事务,事务的传播特性.这个xml文件前面的头部信息可以从另外一个文件(spring-framework-2.0/samples/jpetstore/war/WEB-INF)里面拷过来,这样这个头文件就有了,注意其他的applicationContext拷贝过来它的头部信息可能会少一些,那么有可能影响我们的程序的运行,所以我们用这个里面的头文件.

Java代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2.   
  3. <beans xmlns="http://www.springframework.org/schema/beans"  
  4.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.          xmlns:aop="http://www.springframework.org/schema/aop"  
  6.          xmlns:tx="http://www.springframework.org/schema/tx"  
  7.          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd   
  8.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd   
  9.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">   
  10.     <!-- 配置sessionFactory -->   
  11.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">   
  12.         <property name="configLocation">   
  13.             <value>classpath:hibernate.cfg.xml</value>   
  14.         </property>      
  15.     </bean>            
  16.        
  17.     <!-- 配置事务管理器 -->   
  18.     <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">   
  19.         <property name="sessionFactory">   
  20.             <ref bean="sessionFactory"/>   
  21.         </property>   
  22.     </bean>   
  23.        
  24.     <!-- 配置事务的传播特性 -->   
  25.     <tx:advice id="txAdvice" transaction-manager="transactionManager">   
  26.         <tx:attributes>   
  27.             <tx:method name="add*" propagation="REQUIRED"/>   
  28.             <!--    
  29.             <tx:method name="del*" propagation="REQUIRED"/>   
  30.             -->   
  31.             <tx:method name="*" read-only="true"/>   
  32.         </tx:attributes>   
  33.     </tx:advice>   
  34.        
  35.     <!-- 配置哪些类的哪些方法使用事务 -->   
  36.     <aop:config>   
  37.         <aop:pointcut id="allManagerMethod" expression="execution(* com.xxxx.xxxx.xxxx.*.*(..))"/>   
  38.         <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>   
  39.     </aop:config>   
  40. </beans>  

    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这个里面去找到,然后把中间所有的东西都删掉.剩下的就就像这样:

Java代码
  1. <?xml version="1.0" encoding="ISO-8859-1" ?>   
  2.   
  3. <!DOCTYPE struts-config PUBLIC   
  4.           "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"  
  5.           "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">   
  6.   
  7. <struts-config>      
  8. </struts-config>  

    7.然后我们开始配置我们的web.xml文件,这个文件的配置是最麻烦的,因为我们要控制session的打开和关闭,我们用到了openSessionInView,这个文件可以先从这个地方拿到tomcat/server/webapps/admin/WEB-INF,然后我们把这个文件里面没有用的东西都给它拿掉,留下这些内容:

Java代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <web-app version="2.4"    
  3.     xmlns="http://java.sun.com/xml/ns/j2ee"    
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  5.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee    
  6.     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">   
  7.   <welcome-file-list>   
  8.     <welcome-file>index.jsp</welcome-file>   
  9.   </welcome-file-list>   
  10.      
  11.   <!-- Standard Action Servlet Configuration (with debugging) -->   
  12.   <servlet>   
  13.     <servlet-name>action</servlet-name>   
  14.     <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>   
  15.     <init-param>   
  16.       <param-name>config</param-name>   
  17.       <param-value>/WEB-INF/struts-config.xml</param-value>   
  18.     </init-param>   
  19.     <init-param>   
  20.       <param-name>debug</param-name>   
  21.       <param-value>2</param-value>   
  22.     </init-param>   
  23.     <init-param>   
  24.       <param-name>detail</param-name>   
  25.       <param-value>2</param-value>   
  26.     </init-param>   
  27.     <load-on-startup>2</load-on-startup>   
  28.   </servlet>   
  29.   
  30.   
  31.   <!-- Standard Action Servlet Mapping -->   
  32.   <servlet-mapping>   
  33.     <servlet-name>action</servlet-name>   
  34.     <url-pattern>*.do</url-pattern>   
  35.   </servlet-mapping>   
  36.      
  37.     <context-param>   
  38.         <param-name>contextConfigLocation</param-name>   
  39.         <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>   
  40.      </context-param>   
  41.         
  42.     <listener>   
  43.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>   
  44.     </listener>   
  45.      
  46.     <filter>   
  47.         <filter-name>hibernateFilter</filter-name>   
  48.         <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>   
  49.     </filter>   
  50.        
  51.     <filter-mapping>   
  52.         <filter-name>hibernateFilter</filter-name>   
  53.         <url-pattern>/*</url-pattern>   
  54.     </filter-mapping>    
  55.      
  56.     <filter>   
  57.         <filter-name>Spring character encoding filter</filter-name>   
  58.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>   
  59.         <init-param>   
  60.             <param-name>encoding</param-name>   
  61.             <param-value>GBK</param-value>   
  62.         </init-param>   
  63.     </filter>   
  64.     <filter-mapping>   
  65.         <filter-name>Spring character encoding filter</filter-name>   
  66.         <url-pattern>/*</url-pattern>   
  67.     </filter-mapping>   
  68.      
  69. </web-app>  

    8.现在我们的配置文件写完了,我们的任务完成了.
    9.值得注意的是现在的公司越来越倾向与让你用ssh框架来做一个小的登陆系统,那么这个时候我们就要迅速的不加思索的知道我们要干什么,我们应该怎么去做,不要再在那想上一回,然后再去做,这个东西要相当相当的熟了才行啊.
    10.在这个里面我们主要就是要记住spring的jar包都要加入哪些,然后我们要知道这个事务管理怎么去配置,然后我们要知道这些文件都要在哪个里面去拷贝.

转载地址:http://khici.baihongyu.com/

你可能感兴趣的文章
Love Your Life》—— 热爱生活
查看>>
一个高速交警的忠告
查看>>
新车装饰的中国特色
查看>>
没看过这么NB的自驾游,笑的我眼泪都出来了
查看>>
李涯的哭
查看>>
和机器学习和计算机视觉相关的数学
查看>>
论文MICO for MRI bias field estimation and tissue segmentation品讲
查看>>
后现代
查看>>
VMware6关机后出现is not a valid virtual machine configuration file的解决办法
查看>>
通过ASP实现flash对数据库的访问
查看>>
“==”和equals方法究竟有什么区别?
查看>>
哈佛图书馆墙上的20条训言
查看>>
交流引发深入思考
查看>>
保持我们母语的纯洁
查看>>
免费的互联网时代如何盈利?
查看>>
可怕的宣传力量
查看>>
症状:可以上网,可以上QQ,不能登陆360安全卫士,360浏览器无法同步,有道词典等无法登陆,无法查询。
查看>>
重读《触龙说赵太后》
查看>>
2010的第一次思想触动
查看>>
文学大师做菜艺术20个"须知"
查看>>