1. 程式人生 > >SSH框架學習(二)——引入框架所需配置檔案

SSH框架學習(二)——引入框架所需配置檔案

SSH框架學習(二)——引入框架所需配置檔案

struts2配置檔案

struts2的配置檔案有:
1、web.xml:配置核心過濾器
2、struts.xml:struts本身配置檔案

步驟:
從struts-2.3.15中的black.war拷貝出web.xml和struts.xml
web.xml

  <!-- struts2核心過濾器配置 -->
  <filter>
  	<filter-name>struts</filter-name>
  	<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  
  <filter-mapping>
  	<filter-name>struts</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>

(其中,filter-name命名上下對應)

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>

</struts>

hibernate配置檔案

1、hibernate.cfg.xml:hibernate核心配置檔案(可以被省略)
2、配置對映(後續根據具體操作總結)

spring配置檔案

1、web.xml:配置核心監聽器
2、applicationContext.xml:spring本身配置檔案

web.xml

 <!-- spring核心監聽器配置 -->
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>classpath:applicationContext.xml</param-value>
  </context-param>

applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans    
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
      http://www.springframework.org/schema/context   
      http://www.springframework.org/schema/context/spring-context-2.5.xsd   
      http://www.springframework.org/schema/aop   
      http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   
      http://www.springframework.org/schema/tx   
      http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

</beans>