SSH框架与配置文件的简单搭建

       在eclipse中,对ssh框架进行学习以及简单的编写,以下为基本的项目操作与须知歩骤:

      1、导包(创建项目后的第一步,将所有相关的资源包导入项目WebContent  / WEB-INF/ lib/ 下),找到可能会采用的资源,比如:

               Struts-2.3.30.
           Spring-4.2.2
           Hibernate-5.2.2

            (以上为本例所采用的资源)


            创建一个新的项目(点击File-->New-->Dynamic Web Project):

                                       


       1.1、在Srtuts-2中所需用的jar包中,进行解压,然后复制到项目下(WebContent \ WEB-INF \ lib下):

         

        ( 网上下载,然后找到所需的资源包所在的相应的文件夹,再将其复制导入项目中。)


       1.2、在Spring中所需用到的jar包:

        

         (*根据所需而导入相关资源包,无需用到的jar包可以从中剔除。*)


       1.3、在Hibernate中所需用到的jar包:

        

               还有一个数据库池的包,如果使用c3p0的话,需要导入此包(或者可使用对应的数据库包)。



         2、配置文件的操作


           2.1、 web.xml配置文件

                 写该配置文件时,需要加入Struts2(过滤器)和spring(监听器)两部分。

                  首先是头部信息的处理(可供选择各自的版本);

                  比如:

                     

                    以上详细内容:

                      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xmlns="http://xmlns.jcp.org/xml/ns/javaee"
                       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
                      id="WebApp_ID" version="3.1">

          


            (以下两项配置一并写入 web.xml 中)

                   以下为: struts过滤器的配置


   <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>



                                     spring监听器的配置 
<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>

      

          

       2.2、struts.xml配置文件

  头部信息的部分

        需写上:

           

      

        

               (这是给spring的配置文件和Struts2的配置文件相互的整合)

         

              2.3、action类的继承与配置

                    一般而言,action类都会继承actionSupport :

                  

                  


                  随后紧跟着一句方法(默认为execute);

                   

           

                    

                    以下为action的配置信息:

                    



         

            2.4、appliCation.xml配置文件(以及“bean”的部分),sessionFactory的配置文件,

                  

                 2.4.1、appliCation.xml配置文件

           在appliCation.xml配置中的附带以下信息(置于头部):

       <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">


  接着<bean>部分如下:

                                  


             sessionFactory的配置文件(其中注入了连接池,数据库等信息;采用了hibernate来配置属性):

                       

   

      


             其中如果采用c3p0,其配置文件为:

                   

      

            3、简述在ssh中,数据库的连接

                 按照以下格式列出的数据库连接路径与密码,譬如:

                 

 

                    根据以上的信息,在代码中可以写成:

                     



                   在ssh框架中,关于数据库信息的配置文件内,需要在applicationContext.xml中加上:


                  

                (从而,引入外部属性文件)


                   以上,便是一个简单的例子,简述了ssh框架的搭建与配置文件,在这一基础可去编写程序,从而丰富内容的实现,可供参考。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值