SSI框架学习

目录

SSI框架是指struts、spring、ibatis整合到一起,来构建javaWeb的过程,下面我们从以下几个步骤来说明如何架构javaWeb项目,具体如下:

  1. 加载必须的包
  2. 配置web.xml
  3. jdbc配置
  4. 配置一下文件
    struts.xml、
    ApplicationContext.xml
    SqlMap.xml
    SqlConfig.cml

  5. 业务类


加载必须的包

Struts必须包

struts框架的必须包,我们可以从网上下载下来,网上所下载下来的包,我们可以发现,

这里写图片描述

这里面有很多包,但并不是所有都是我们必须要的,我们只需要导入我们所需要的包即可,如下图所示,

这里写图片描述

Spring必须包

对于Spring架包同样可以从网上下载可得,我们这里只给出他的必须包,

这里写图片描述

iBatis必须包

对于iBatis必须包只有一个,iBatis主要负责对数据库的关联和操作的,如下图所示,

这里写图片描述

mysql数据库驱动包

常用的数据库有DB2、Oracle、mysql等等,对于个人所应用的一般为mysql,而企业所用大多为前两种,这里驱动mysql的包为:

mysql-connector-java-5.16.jar

根据自己所用的mysql版本,选用所对应的架包。

其他必须包

下面给出一些其他用到的数据包

这里写图片描述

  • c3p0 :数据库连接池
  • dom4j : 解析xml文件
  • log4j :日志文件的架包
  • struts2-spring-plugin :绑定struts和spring的架包

对于以上架包,我们直接将jar文件复制到 webcontent/web-inf/lib文件夹下面,刷新即可导入架包

配置web.xml

导入架包之后,我们需要在web.xml文件里面配置struts和spring

Struts的配置

在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配置

在web.xml文件中配置Spring,而web.xml文件中配置的内容有前后顺序之别,而Spring文件的配置内容需在Struts的内容后面,即

<!-- 配置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 -->
  <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <listener>
        <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>
  </listener>

配置jdbc

配置jdbc主要是给出数据库的相关属性文件,来连接数据库,这部分是spring来连接数据池的,该文件的内容主要用来连接数据库
jdbc.properties:

jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/数据库名字
jdbc.username=root
jdbc.password=密码

对于默认的数据库,数据库名字为root,密码为自己安装时所用的密码,而127.0.0.1位当地网址,对于远程的数据库,则需要用远程的地址,3306为数据库的端口号。
对于其他不同的数据库,各自有不同的配置文件。

注意:属性的前后左右不能有空格!!!不然会出现错误。

ssi文件配置

配置struts

根据个人理解,该文件的作用主要是用来部署前端表单所用来连接的action,首先给出空的struts.xml文件。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <constant name="struts.objectFactory" value="spring" />    
    <constant name="struts.i18n.encoding" value="UTF-8" />    
    <constant name="struts.i18n.reload" value="false" />    
    <constant name="struts.configuration.xml.reload" value="false" />    
    <constant name="struts.custom.i18n.resources" value="globalMessages" />    
    <constant name="struts.action.extension" value="action,," />    

    <constant name="struts.convention.package.locators.basePackage"    
              value="com.neusoft.demo.action" />    
    <constant name="struts.convention.result.path" value="/" />    
    <constant name="struts.serve.static" value="true" />    
    <constant name="struts.serve.static.browserCache" value="false" />    

</struts>  

其中,constant为常用的参数配置,而


<constant name="struts.convention.package.locators.basePackage"
value="com.neusoft.demo.action" />

该配置文件中,value为action所在的包

配置spring的文件

spring的配置文件为applicationContext.xml,该文件作用非常重要,用来配置数据库连接池,配置数据库与具体类的连接,具体类与前端的连接。即数据层 —实体—前端的连接,该Context文件需要在web.xml文件中进行配置。
在web.xml文件中配置context(上下文),添加如下代码,该配置内容在web.xml文件的最前端, 并给出中文过滤器。

web.xml文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值