web配置清单

一、JDK
  下载安装JDK1.6+
  设置环境变量JAVA_HOME=C:\Program Files\Java\jdk1.6.0_06
              CLASSPATH=C:\Program Files\Java\jdk1.6.0_06\lib;C:\Program Files\Java\jdk1.6.0_06\jre\lib;
二、Tomcat
  下载安装Tomcat6+
  设置环境变量CATALINA_HOME=D:\tomcat

三、Eclipse
  下载安装Eclipse3.4+
  设置Tomcat服务器 Window->Preferences->Tomcat
        Tomcat version = Version 6.x
        Tomcat home = D:\tomcat
        Context declaration mode = Server.xml
        Configuration file = D:\tomcat\confg\server.xml
        (如果系统装有MyEclipse,注意修改JVM Setting中JRE = jdk1.6+)

四、Project
  创建Web Dynamic Project
  设置Build Path = {Project}/WebContent/WEB-INF/classes

五、Spring
  下载Spring2.5.6
  1、Library
     将以下类包拷贝至WEB-INF/lib
        核心包:spring.jar
        依赖包:commons-*、cglib、dom4j、javassist、slf4j、aopalliance
  2、applicationContext.xml
     在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"
                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">
     </beans>
  3、Web.xml
     修改Web.xml,增加如下内容:
     <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/applicationContext.xml</param-value>
     </context-param>
     <listener>
                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>

六、Hibernate
  下载Hibernate3.1,以下主要整合spring框架进行配置。
   1、Library
     将以下类包拷贝至WEB-INF/lib
        核心包:hibernate3.jar
        依赖包:commons-*、dom4j、ojdbc14.jar(Oracle数据库驱动,其他数据库另选)
   2.Datasource、Connection和JNDI
     在META-INF/目录下创建context.xml,配置数据库连接池参数,内容如下:   
     <?xml version="1.0" encoding="UTF-8"?>
     <Context reloadable="true" crossContext="true">
        <WatchedResource>WEB-INF/web.xml</WatchedResource>
        <Resource name="ojdbc/oracle"
                  auth="Container"
          type="javax.sql.DataSource"
                  driverClassName="oracle.jdbc.driver.OracleDriver"
          url="jdbc:oracle:thin:@192.168.0.211:1521:orcl"
                  username="demo"
          password="1234"
          maxActive="10"
                  maxIdle="100"
                  maxWait="1000">
        </Resource>
      </Context>   
     修改Web.xml,增加以下内容:
        <resource-ref>
                <description>DB Connection</description>
                <res-ref-name>ojdbc/oracle</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
        </resource-ref>
   3、applicationContext.xml
     修改applicationContext.xml,增加如下内容:
     <!-- 本地连接池配置 -->
     <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="java:comp/env/ojdbc/oracle" />
     </bean>
     <!-- 配置sessionFactory, 注意这里引入的包的不同  -->
     <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="hmyDataSource"></property>
            <property name="hibernateProperties">
                 <props>
                     <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
                     <prop key="hibernate.show_sql">false</prop>
                 </props>
            </property>
        <!-- 配置hibernate相应的映射文件, 以User为例 -->
            <property name="mappingResources">  
                 <list>
                      <value>com/company/User.hbm.xml</value>
                 </list>
            </property>
     </bean>
   4、Mapping
     对应Java文件和配置xml文件必须在同一目录,以User为例(User.java文件略),
     User.hbm.xml内容如下:
     <?xml version="1.0" encoding="UTF-8"?>
     <!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.company.User" table="T_USER">
                <id name="id" type="java.lang.Long">
                    <column name="ID" precision="10" scale="0" />
                    <generator class="sequence" />
                </id>
        <property name="name" type="java.lang.String">
            <column name="NAME" length="50" />
        </property>
                ......
          </class>
     </hibernate-mapping>
七、Struts2
  下载Struts2.1.6
   1、Library
     将以下类包拷贝至WEB-INF/lib
        核心包:Struts2.1.6.jar
        依赖包:commons-logging,freemaeker,ognl,struts2-core,xwork,struts2-spring-plugin-2.1.6.jar(与spring整合插件);
   2、struts.xml
     在src目录下struts.xml文件,主要内容如下:
     <?xml version="1.0" encoding="UTF-8"?>
     <!DOCTYPE struts PUBLIC
           "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
           "http://struts.apache.org/dtds/struts-2.0.dtd">
     <struts>
          <package name="tutorial" extends="struts-default">
                <!-- Add your actions here -->
          </package>
     </struts>
   3、web.xml
     修改Web.xml,增加如下内容:
     <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>

posted @ 2010-04-13 18:41  云端小飞象cg  阅读(209)  评论(0编辑  收藏  举报