• ssh 的搭建


    struts包的下载:http://struts.apache.org/download.cgi#struts252

    string包的下载:

    http://repo.spring.io/release/org/springframework/spring/%20

    hibernate包的下载:http://hibernate.org/orm/

    一、先下载好包

    二、创建一个项目text

    三、导入struts2 和spring

     

     然后编辑xml

    struts的版本是2.3.3的

      <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>
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
      </context-param>
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    

     编写一个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">
    <!-- 上面的头,注意版本,从样例里复制过来 showcase.warWEB-INFsrcjavastruts.xml -->
    
    <struts>
    
        <package name="mypck001" extends="struts-default">
            
            <action name="Index" class="myIndexAction" method="execute1">
                <result name="success">/WEB-INF/jsp/index2.jsp</result>
                <result name="error">/WEB-INF/jsp/s_tag.jsp</result>
            </action>
        </package>
    </struts>
    <?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">
    <!-- 上面的头,注意版本,从样例里复制过来 showcase.warWEB-INFsrcjavastruts.xml -->
    
    <!-- include文件用于分割,实现多人并发不冲突 -->
    <struts>
    	<!-- 告知Struts2运行时使用Spring来创建对象 -->
    	<constant name="struts.objectFactory" value="spring" />
    	<include file="s001.xml" />
    	<include file="s002.xml" />
    	<include file="s003.xml" />
    </struts>
    

      

     然后添加src下创建applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!--头信息,注意你的spring版本号  -->
    <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:context="http://www.springframework.org/schema/context"  
    	xmlns:jee="http://www.springframework.org/schema/jee"  
    	xmlns:tx="http://www.springframework.org/schema/tx"  
    	xsi:schemaLocation="
    	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd  
    	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd  
    	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
    	http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd  
    	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">
    

    在里面配置以下代码

    <bean id="myIndexAction" class="ssh.action.IndexAction" scope="prototype">
    		<!-- setIs(myIndexService) -->
    		<property name="is" ref="myIndexService"/>
    	</bean>
    	
    	<!-- myIndexService = new ssh.service.IndexServiceImpl() -->
    	<bean id="myIndexService" class="ssh.service.IndexServiceImpl" scope="prototype">
    		<property name="id" ref="myIndexDao"/>
    	</bean>
    	
    	<bean id="myIndexDao" class="ssh.dao.IndexDaoImpl" scope="prototype">
    		<property name="c" ref="myConnection"></property>
    	</bean>
    	
    	<bean id="myConnection" class="ssh.util.MyConnectionImpl_SQLSERVER" scope="prototype">
    	</bean>
    

      配置hibernate代码

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    
    <hibernate-configuration>
    	<session-factory>
    		<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    		<property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=CardDB</property>
    		<property name="connection.username">sa</property>
    		<property name="connection.password"></property>
    		<!-- 每个数据库都有1个 -->
    		<property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
    		<property name="connection.pool_size">5</property>
    		<property name="show_sql">true</property>
    		<property name="format_sql">true</property>
    		<property name="hbm2dll.auto">update</property>		
    	</session-factory>
    </hibernate-configuration>
    

     

     框架基本搭建完成。

  • 相关阅读:
    Java架构师必备技能:docker使用大全
    SpringBoot+ShardingSphere彻底解决生产环境数据库字段加解密问题
    记一次最近生产环境项目中发生的两个事故及处理方法
    【Java分享客栈】一个包装过简历的新同事写完微信支付引起事故后果断离职了
    【Java分享客栈】我为什么极力推荐XXLJOB作为中小厂的分布式任务调度平台
    StandardScaler/MinMaxScaler/Normalizer
    Vue开发配置
    如何从邮箱中批量下载距离当天最近一天的邮件附件.
    JavaScript获取页面上某个元素的方法
    OI小技巧
  • 原文地址:https://www.cnblogs.com/gushendanying/p/5856130.html
Copyright © 2020-2023  润新知