基于SSH框架全注解简单实例

第一步:导jar包,全套jar包需求私我留言基于SSH框架全注解简单实例_第1张图片
基于SSH框架全注解简单实例_第2张图片

第二部:配置文件(我只演示基础配置,可根据自己的需求添加)

 1. web.xml文件

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>TJ-searchdisplay-name>
  <welcome-file-list>
    <welcome-file>index.htmlwelcome-file>
    <welcome-file>index.htmwelcome-file>
    <welcome-file>index.jspwelcome-file>
    <welcome-file>default.htmlwelcome-file>
    <welcome-file>default.htmwelcome-file>
    <welcome-file>default.jspwelcome-file>
  welcome-file-list>
     
  <context-param>  
        <param-name>contextConfigLocationparam-name>  
        <param-value>  
            classpath:applicationContext.xml  
        param-value>  
    context-param>  

   <listener>  
     <listener-class>  
         org.springframework.web.context.ContextLoaderListener  
     listener-class>  
 listener>  
   
 <filter>  
    <filter-name>struts2filter-name>  
    <filter-class>  
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
    filter-class>  
    <init-param>  
                 
                <param-name>actionPackagesparam-name>   
                <param-value>pers.tj.search.actionparam-value>   
    init-param>   
  filter>  

  <filter>
    <filter-name>SpringOpenSessionInViewFilterfilter-name>
        <filter-class>
            org.springframework.orm.hibernate4.support.OpenSessionInViewFilter 
        filter-class> 
  filter>

  <filter-mapping>  
        <filter-name>struts2filter-name>  
        <url-pattern>/*url-pattern>  
  filter-mapping>
  <display-name>display-name>

  

web-app>
 2. truts.xml文件


    <struts>
          
        <constant name="struts.devMode" value="false" />  
          
        <constant name="struts.objectFactory" value="spring" />  
          
        <constant name="struts.i18n.encoding" value="UTF-8" />   
          
        <constant name="struts.i18n.reload" value="false" />  
          
        <constant name="struts.configuration.xml.reload" value="false" />  
          
        
          
        <constant name="actionPackages" value="pers.tj.search.action"/>
    struts>
 3. applicationContext.xml文件

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

      
    <context:annotation-config />  
       
    <context:component-scan base-package="pers.tj.search" />

    
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver">property>
        <property name="url" value="jdbc:oracle:thin:@192.168.116.128:1521:orcl">property>
        <property name="username" value="TJSearch">property>
        <property name="password" value="tjadmin">property>
    bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource"/>
        property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.Oracle9Dialect
                prop>
                <prop key="hibernate.show_sql">trueprop>
                <prop key="hibernate.format_sql">trueprop>
            props>
        property>
        <property name="packagesToScan">  
            <list>  
                <value>pers.tj.search.beanvalue>  
            list>  
        property>
    bean>

      
    <bean id="transactionManager"  
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource"/>
    bean>

    
     <tx:annotation-driven transaction-manager="transactionManager" />
beans>

第三部:代码开发
当配置文件发不到服务器上运行不报错,就可以进行源码开发了,当然配置xml文件时可能会遇到各种小问题,这是基于spring4.3.7+hibernate4.3.1+struts2.3.3框架演示。

你可能感兴趣的:(java-web,ssh框架搭建)