ssi配置
最近公司用到了ssi,给大家介绍下,和ssm不同他是4层逻辑。。。
添加配置文件
我们首先从web.xml文件说起
web.xml加载过程:
1 启动WEB项目的时候,容器(如:Toat)会读他的配置文件web.xml读两个节点 <listener></listener>和<contt-param></context-param> 2 紧接着,容器创建一个ServletContext(上下文) 这个WEB项目所有部分都将共享这个上下文 3 容器将<context-param></context-param>转化为键值对并交给ServletContext 4 容器创建<listener></listener>中的类的实例,即创建监听 5 在监听中会有contextInitialized(ServletContextEvent args)初始化方法,在这个方法中获得: ServletContext = ServletContextEvent.getServletContext(); context-param的值 = ServletContext.getInitParameter("context-param的键");web.xml节点加载顺序 节点的加载顺序与它们在web.xml文件中的先后顺序无关。即不会因为filter写在listener的前面而会先加载filter最终得出的结论是:listener->filter->servlet 同时还存在着这样一种配置节点:context-param,它用于向 ServletContext 提供键值对,即应用程序上下文信息。我们的 listener, filter 等在初始化时会用到这些上下文 的信息,那么context-param 配置节是不是应该写在 listener 配置节前呢?实际上 context-param 配置节可写在任意位置,因此真正的加载顺序为:
context-param -> listener -> filter -> servlet 加载spring <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> 最终结论:web.xml 的加载顺序是:[context-param -> listener -> filter -> servlet -> spring] ,而同类型节点之间的实际程序调用的时候的顺序是根据对应的 mapping 的顺序进行调 用的。
打开web.xml文件,根据实际需要添加如下内容
在这说说SSI整合时的一些配置文件:webAppRootKey /WEB-INF/log4j.properties contextConfigLocation /WEB-INF/beans.xml org.springframework.web.util.Log4jConfigListener org.springframework.web.context.ContextLoaderListener
1,contextConfigLocation:Spring容器启动时需要加载Spring的配置文件。默认是/WEB-INF目录下的applicationContext.xml文件
当然也可以放在classpath下,可以包括多个spring配置文件,这就得依靠contextConfigLocation
contextConfigLocation /WEB-INF/beans.xml
如果web.xml中没有配置context-param,spring的配置就像如上这段代码示例一下,自动去WEB-INF目录下寻找applicationContext.xml。此时,如果你修改applicationContext.xml的名称,或者移除它,再启动服务器,你会得到如下异常信息:
1.nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
这证实了其默认配置。默认配置情况下spring只会去WEB-INF目录下寻找配置文件,而不会去classpath下寻找。
如果我们不想将配置文件放在WEB-INF目录下呢?开发中经常在src下面创建一个config目录,用于存放配置文件。此时,对应的param-value改为:classpath:config/applicationContext.xml。一定要加上classpath,这告诉spring去classes目录下的config目录下面寻找配置文件。2,如何启动Spring容器两种方法,一种以listener启动 一种以load-on-startup Servlet。
org.springframework.web.context.ContextLoaderListener
第二种
context org.springframework.web.context.ContextLoaderServlet 1
3,整合Struts2
4,Spring整合ibatis配置文件struts2 org.apache.struts2.diser.ng.filter.StrutsPrepareAndExeeFilter struts2 /*
5,Struts.xmlclasspath:SqlMapConfig.xml
constant配置struts的常量(也可在struts.properties)文件中配置,将struts的对象工厂托由spring管理。