SSH基本配置文件示例

一,web.xml配置

主要需要配置struts2的過濾器和spring的配置文件

<?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"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<!-- struts2的過濾器 -->
<display-name>struts_day03</display-name>
<filter>
<filter-name>struts2Filter</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 加載配置文件 -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 監(jiān)聽器 -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
  <welcome-file>index.html</welcome-file>
  <welcome-file>index.htm</welcome-file>
  <welcome-file>index.jsp</welcome-file>
  <welcome-file>default.html</welcome-file>
  <welcome-file>default.htm</welcome-file>
  <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

二艾岂,spring.xml配置

主要配置的是數(shù)據(jù)源和sessionFactory,以及一些需要掃描的類

<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
 
   <!-- 導(dǎo)入資源文件 -->
   <context:property-placeholder location="classpath:db.properties"/>
 
 <!-- 配置數(shù)據(jù)源 -->
 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
     <property name="user" value="${jdbc.user}"></property>
     <property name="password" value="${jdbc.password}"></property>
     <property name="driverClass" value="${jdbc.driverCalss}"></property>
     <property name="jdbcUrl" value="${jdbc.url}"></property>
     <property name="initialPoolSize" value="${jdbc.initialPoolSize}"></property>
     <property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property>
 </bean>
 
 <!-- 配置hibernate的SessionFactory實(shí)例:通過spring的LocalSesionFactoryBean進(jìn)行配置 -->
 <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
     <!-- 關(guān)聯(lián)數(shù)據(jù)源 -->
     <property name="dataSource" ref="dataSource"></property>
     <!-- 配置hibernate.cfg.xml文件的位置和名稱 -->
     <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
     <!-- 實(shí)體類的配置(*.hbm.xml)的配置 -->   
     <property name="mappingLocations" value="classpath:com/wxhl/edu/entity/*.hbm.xml"></property>
 </bean>
 <bean id="userDao" class="com.wxhl.edu.dao.impl.UserDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <bean id="userService" class="com.wxhl.edu.service.impl.UserServiceImpl">
        <property name="userDao" ref="userDao"></property>
 </bean>
 <bean id="user-manager" class="com.wxhl.edu.action.UserManagerAction" scope="prototype">
    <property name="userService" ref="userService"></property>
 </bean>
 
 <bean class="com.wxhl.edu.entity.User"></bean>
</beans>

三,hibernate.cfg.xml配置

主要是sessionFactory的初始化屬性

<?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-factory>
        <!-- hibernate的基本屬性: 方言,sql顯示方式鞍帝,格式化sql,表的生成策略 -->
        <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>

四,struts.xml配置

主要是一些action的配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
  "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.configuration.xml.reload" value="true" />
<constant name="struts.custom.i18n.resources" value="i18n" />
<package name="custom-default" namespace="/user" extends="struts-default">
    <action name="add" class="user-manager" method="add">
        <result name="Add">/addUser.jsp</result>
    </action>
    <action name="update" class="user-manager" method="update">
        <result name="Update">/updateUser.jsp</result>
    </action>
    <action name="delete" class="user-manager" method="delete">
        <result name="Delete">/listUser.jsp</result>
    </action>
    <action name="list" class="user-manager" method="list">
        <result name="list">/listUser.jsp</result>
    </action>
    <action name="saveUser" class="user-manager" method="save">
        <result name="save">/listUser.jsp</result>
    </action>
    <action name="updateUser" class="user-manager" method="updateUser">
        <result name="updateUser">/listUser.jsp</result>
    </action>
</package>
</struts>

五煞茫,持久化層的類名.hbm.xml配置

主要是一些查詢語句

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.wxhl.edu.entity.User" table="tb_USER">
    <id name="userId" type="java.lang.Integer">
        <column name="USERID" />
        <generator class="native" />
    </id>
    <property name="userName" type="java.lang.String">
        <column name="USER_NAME" />
    </property>
    <property name="age" type="java.lang.Integer">
        <column name="AGE" />
    </property>
    <property name="no" type="java.lang.String">
        <column name="NO" />
    </property>
    <property name="class_grade" type="java.lang.String">
        <column name="CLASS_GRADE" />
    </property>
</class>
</hibernate-mapping>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末帕涌,一起剝皮案震驚了整個(gè)濱河市岩臣,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌宵膨,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,576評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件炸宵,死亡現(xiàn)場(chǎng)離奇詭異辟躏,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)土全,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,515評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門捎琐,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人裹匙,你說我怎么就攤上這事瑞凑。” “怎么了概页?”我有些...
    開封第一講書人閱讀 168,017評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵籽御,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我惰匙,道長(zhǎng)技掏,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,626評(píng)論 1 296
  • 正文 為了忘掉前任项鬼,我火速辦了婚禮哑梳,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘绘盟。我一直安慰自己鸠真,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,625評(píng)論 6 397
  • 文/花漫 我一把揭開白布龄毡。 她就那樣靜靜地躺著吠卷,像睡著了一般。 火紅的嫁衣襯著肌膚如雪稚虎。 梳的紋絲不亂的頭發(fā)上撤嫩,一...
    開封第一講書人閱讀 52,255評(píng)論 1 308
  • 那天,我揣著相機(jī)與錄音蠢终,去河邊找鬼序攘。 笑死,一個(gè)胖子當(dāng)著我的面吹牛寻拂,可吹牛的內(nèi)容都是我干的程奠。 我是一名探鬼主播,決...
    沈念sama閱讀 40,825評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼祭钉,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼瞄沙!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,729評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤距境,失蹤者是張志新(化名)和其女友劉穎申尼,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體垫桂,經(jīng)...
    沈念sama閱讀 46,271評(píng)論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡师幕,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,363評(píng)論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了诬滩。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片霹粥。...
    茶點(diǎn)故事閱讀 40,498評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖疼鸟,靈堂內(nèi)的尸體忽然破棺而出后控,到底是詐尸還是另有隱情,我是刑警寧澤空镜,帶...
    沈念sama閱讀 36,183評(píng)論 5 350
  • 正文 年R本政府宣布浩淘,位于F島的核電站,受9級(jí)特大地震影響吴攒,放射性物質(zhì)發(fā)生泄漏馋袜。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,867評(píng)論 3 333
  • 文/蒙蒙 一舶斧、第九天 我趴在偏房一處隱蔽的房頂上張望欣鳖。 院中可真熱鬧,春花似錦茴厉、人聲如沸泽台。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,338評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽怀酷。三九已至,卻和暖如春嗜闻,著一層夾襖步出監(jiān)牢的瞬間蜕依,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,458評(píng)論 1 272
  • 我被黑心中介騙來泰國打工琉雳, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留样眠,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,906評(píng)論 3 376
  • 正文 我出身青樓翠肘,卻偏偏與公主長(zhǎng)得像檐束,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子束倍,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,507評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容