002-web.xml配置其他框架
1.配置spring
1.1.步骤
    1、加载配置文件。
    2、设置启动方式。
1.2.加载配置文件
  web-inf下加载单个文件:
  <context-param>
	     <param-name>contextConfigLocation</param-name>
	     <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>
  web-inf/classes下加载多个文件:
  <context-param>
	     <param-name>contextConfigLocation</param-name>
	     <param-value>classpath*:**/applicationContext*.xml</param-value>
  </context-param>
  其中“**/applicationContext*.xml”表示任意目录下的以“applicationContext”开头的xml配置文件。
  不推荐使用任意路径,推荐使用使用applicationContext*.xml
  如果加载多个文件,用逗号隔开。
1.3.设置启动方式
    spring启动方式有三种:
      ContextLoaderListener(推荐)
      ContextLoaderServlet(spring3.0版本以上不支持)
      ContextLoaderPlugIn(string2.0版本以上不支持)
1.3.1.ContextLoaderListener
      <listener>
	        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener> 
1.3.2.ContextLoaderServlet
      <servlet>
        <servlet-name>context</servlet-name>
        <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
此方式是为了给不支持监听的web容器使用。
1.3.3.ContextLoaderPlugIn
      <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
            <set-property property="contextConfigLocation"   value="/WEB-INF/applicationContext.xml"/>
      </plug-in>
      此方式需求导入:org.springframework.web.struts-3.0.5.RELEASE.jar
      此包在struts2.0以后不支持。
2.配置struts1
2.1.步骤
    1、配置ActionServlet。
    2、配置Struts标签库?。
    3、配置欢迎文件清单。
    4、配置错误处理。
2.2.配置ActionServlet
    <servlet>
             <servlet-name>action</servlet-name>
             <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
      <init-param>
                 <param-name>config</param-name>
                 <param-value>/WEB-INF/struts-config.xml</param-value>
            </init-param>
      <init-param>
        <param-name>debug</param-name>
                <param-value>3</param-value>
            </init-param>
      <init-param>
        <param-name>detail</param-name>
        <param-value>3</param-value>
      </init-param>
      <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
      <servlet-name>action</servlet-name>
      <url-pattern>*.do</url-pattern>
    </servlet-mapping>
1、不管应用中包含多少个子应用,都只需配置一个ActionServlet,因为ActionServlet支持多线程,且目前的Struts框架只允许在应用中配置一个ActionServlet。
    2、<init-param>
        <param-name>config</param-name> 
        <param-value>WEB-INF/struts-config.xml</param-value>
      </init-param>
       这里是以相对路径的方式指明Struts应用程序的配置文件位置。如不设置,则默认值为/WEB-INF/struts-config.xml。
       当多人协作开发项目时可以对Strutst的配置文件进行适当的扩充,但必须为config开头。如:
      <init-param>
        <param-name>config/XXXXXXXXX</param-name>
        <param-value>/WEB-INF/XXXXX.xml</param-value>
      </init-param>
      配置多个文件,param-name的值必须以config开头。
      root url 后紧跟XXXXXXXXX访问当前配置。
    3、<init-param>
        <param-name>debug</param-name>
        <param-value>3</param-value>
      </init-param>
      设置Servlet的debug级别,控制日志记录的详细程度。默认为0,记录相对最少的日志信息。
    4、<init-param>
        <param-name>detail</param-name>
        <param-value>3</param-value>
      </init-param>
     设置Digester的debug级别,Digester是Struts框架所使用的用来解析xml配置文件的一个框架,通过该设置,可以查看不同详细等级的解析日志。默认为0,记录相对最少的日志信息。
    5、<servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
        </servlet-mapping>
就是将所有的*.do请求提交给action,从这里又找到上面那个配置可以读到ActionServlet的位置。
6、<load-on-startup>0</load-on-startup>
ActionServlet在服务器开启时加载的次序,数值越低,越先加载。
2.3.配置Struts标签库
    <taglib>
         <tag-uri>/WEB-INF/struts-html.tld<tag-uri>
         <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib>
    tag-uri:用于指定标签库的相对或者绝对URI地址,Web应用根据这一URI来访问标签库。
    taglib-location:指定标签描述文件在文件资源系统中的物理位置。
2.4.配置欢迎文件清单
  当客户访问Web应用时,如果仅仅给出Web应用的Root?URL,没有指定具体的文件名。Web容器会自动调用Web应用的欢迎文件。<welcome-file-list>是用来设置此项. 
  <welcome-file-list>
    <welcome-file>welcome.jsp</welcome-file>
  </welcome-file-list>
  说明:在<welcome-file-list>下可以有多个<welcom-file>。Web容器会依次寻找欢迎界面,直到找到为止。但如果不存在会向客户端返回”HTTP  404  NOT  Found“错误信息。 
  由于在<welcome-file-list>元素中不能配置Servlet映射,则不能直接把Struts的Action作为欢迎文件。
  A:welcome.jsp页面(可换文件名)
      <script language=”javascript”>location.href=”xxxx.do”</script>
  B:web.xml 
    <welcome-file-list>
    <welcome-file>welcome.jsp</welcome-file>
    </welcome-file-list>
C、struts1中配置xxxx.do
2.5.配置错误处理
Struts框架中不能处理所有的错误或异常。当Struts框架发生不能处理所有的错误或异常时,就把错误抛给Web容器。在默认情况下,Web容器会向用户浏览器直接返回原始的错误.
3.配置struts2
3.1.步骤
    1、配置filter.
    2、配置欢迎文件清单。
    3、配置错误处理。
3.2.配置filter
  <filter>
    <filter-name>strutsfilter</filter-name>
    <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>strutsfilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
配置内容还有<init-param>等设置过滤器初始化参数的。之所以这里没有具体解释,是因为这些也可以在struts.properties文件内定义。
3.3.配置欢迎文件清单。
同struts1
3.4.配置错误处理。
同struts1
4.配置log4j
spring动态改变log4j记录级别和策略,即不用重启项目修改。
4.1.步骤
    1、配置项目发布路径。
    2、配置配置文件路径。
    3、配置扫描文件时间。
    4、配置监听。
4.2.配置项目发布路径
    <context-param>   
          <param-name>webAppRootKey</param-name>   
           <param-value>webapp.root</param-value>   
    </context-param>   
 
    项目发布路径,同一中间件容器此配置的param-value的值不能一样。默认配置为:webapp.root
    Java可通过System.getProperty("webapp.root")。
    Log4j.propertis可通过${ webapp.root }值为(假若中间件为tomcat):tomcat安装目录/tomcat/webapps/项目名称
4.3.配置配置文件路径
    <context-param>   
        <param-name>log4jConfigLocation</param-name>   
        <param-value>/WEB-INF/classes/log4j.properties</param-value>   
    </context-param> 
类路径:<param-value>classpath:log4j.properties</param-value>
4.4.配置扫描文件时间(单位毫秒)
    <context-param>   
        <param-name>log4jRefreshInterval</param-name>   
        <param-value>6000</param-value>   
    </context-param>
4.5.配置监听
  <listener>   
      <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>   
  </listener> 
5.配置dwr
                    
                
                
            
        
浙公网安备 33010602011771号