SSH+MVC的配置文件详解

来源:互联网 发布:deepin 添加ubuntu 源 编辑:程序博客网 时间:2024/06/14 14:24

SSH+MVC的配置文件详解

1.Struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
//开发模式,默认为false,如果为true的话可能会影响js,jQuery的取值;好处是更改struts不用重新部署服务
<constant name="struts.devMode" value="false"></constant>
//继承默认的struts-default
<package name="default" extends="struts-default" namespace="/">
//action 名字 class类名
<action name="" class="" >
</action>
//返回的jsp即类型
<result name=""  type="" >xxx.jsp</result>
</package>
</struts>    
二hibernate

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
//session工厂
<session-factory>
//导入相关oracle的类
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
//url路径jdbc:oracle:thin:@localhost:1521:oracle
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:oracle</property>
//数据库的用户名
<property name="connection.username">scott</property>
//数据库的密码
<property name="connection.password">Oracle11g</property>
//数据库的驱动类
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
//连接名
<property name="myeclipse.connection.profile">db</property>
//显示sql语句
<property name="show_sql">true</property>
//加载对应的实体类
<mapping resource="xxx/xxx/xxx/xxx.hbm.xml" />
</session-factory>
</hibernate-configuration>


三Spring

<?xml version="1.0" encoding="UTF-8"?>
<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: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/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
">

//配置sessionFactory类

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

//在spring中拿到hibernate的session

<property name="configLocations">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
//开启事物
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
//配置Spring AOP 开启事物的方式REQUIRED
<tx:advice id="advice" transaction-manager="transactionManager">
<tx:attributes>
//对于所有的方法
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
//配置切入点对于执行切入的方法execution(* com.zt.service.*.*(..))
<aop:config>
<aop:pointcut expression="execution(* com.zt.service.*.*(..))" id="myPointcut"/>
<aop:advisor advice-ref="advice" pointcut-ref="myPointcut"/>
</aop:config>

//配置Action的类scope="prototype" 创建多例
<bean id="xxx" class="xxxxxxxxxxxxx" scope="prototype">
//action中的service类
<property name="xxxxxxxx" ref="xxxxxService"></property>
</bean>
//配置 Service的类
<bean id="xxx" class="xxxxxxxxxxxxxServiceImpl">
//Service中的DAO类
<property name="xxx" ref="xxx"></property>
</bean>
//配置DAO
<bean id="xxxx" class="xxxxDAOmpl">
//配置sessionFactory
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

</beans>

四WEB配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
//拦截applicationContext-*.xml的配置文件
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>

//Spring的监听
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
//登陆的jsp
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>
//struts2的配置
  <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></web-app>






0 0
原创粉丝点击