zoukankan      html  css  js  c++  java
  • Java开发环境搭建

    在搭建环境之前得先把Tomcat配置(本人选择的是6.0)

    1、新建Web项目,名字自己取 如:SSH

    2、在WebContent/WEB-INF目录下创建web.xml文件,增加Struts2拦截器,如下代码:
    <?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">
     <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
     <filter>
     <filter-name>struts2</filter-name>
     <filter-class>
     org.apache.struts2.dispatcher.FilterDispatcher
     </filter-class>
     </filter>
     <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>
      
     
    </web-app>
    3、配置Spring环境,先讲配置文件的写法,后面统一的引入三个框架所需要的Jar包。我们在前面的web.xml中增加Spring的监听器,代码如下
    <listener>
       <listener-class>
        org.springframework.web.context.ContextLoaderListener
        </listener-class>
        </listener>
        <context-param>
          <param-name>contextConfigLocation</param-name>
             <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
     </context-param>
    4、在WebContent/WEB-INF目录下创applicationContext.xml文件:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans
     xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

      
        <!-- 数据库-配置数据连接池 -->
        <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDatasources">
        <property name="driverClassName"
          value="com.mysql.jdbc.Driver">
          </property>
          <property name="url"
          value="jbdc:mysql://localhost:3306/dbssh;databaseName=admin">
          </property>
          <property name="username" value="root"></property>
          <property name="password" value="123456"></property>
          <property name="maxActive" value="100"></property>
          <property name="maxWait" value="500"></property>
          <property name="defaultAutoCommit" value="true"></property>
          </bean>
        <!-- sessionFactory配置与管理 -->
        <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="hibernateProperties">
       <props>
        <prop key="hibernate.dialect">
         org.hibernate.dialect.MySQLDialect
        </prop>
        <prop key="hibernate.show_sql">true</prop>
       </props>
      </property>

        <property name="mappingResources">
        <list>
        <value>com/crm/bean/Customer.hbm.xml
        </value>
        </list>
        </property>
        </bean>
        <!-- 配置Dao -->
        <bean id="CustDao" class="com.crm.dao.impl.CustDaoImpl">
        <property name="sessionFactory">
        <ref bean="sessionFactory"></ref>
        </property>
        </bean>
     </beans>

    5.配置Hibernate

    添加必需jar

    添加映射文件和DAO层代码

    要使用的jar包引入工程中的WEB-INF/lib目录中,然后将项目加入到Tomcat中启动运行看控制台是否有错误产生,如果没有错误即环境搭建完成

  • 相关阅读:
    [zz]Ubuntu源签名错误/Ubuntu 更新源签名错误 –BADSIG 40976EAF437D05B5
    [zz]GNU C __attribute__ 机制简介
    [zz]为小米创建虚拟机路由器
    liburcu 库
    多代理集群调度:可伸缩性和灵活性
    automake的使用速查
    automake之简单的例子
    ajax原生
    Cookie 和Session 的原理
    路径问题
  • 原文地址:https://www.cnblogs.com/vincent-chan/p/7087530.html
Copyright © 2011-2022 走看看