搭建Web项目

来源:互联网 发布:ifconfig修改mac地址 编辑:程序博客网 时间:2024/04/30 15:40

搭建web 项目环境

1、windows平台

2、运行环境:Tomcat6.0、JDK6.0

3、开发环境:Eclipse

4、使用技术框架:SpringMVC 、Hibernate

5、使用数据库:SQLServer2008

SpringMVC+hibernate 对应的配置:application.xml,zd_servlet.xml,web.xml等配置文件信息

zd_servlet.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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
    xmlns:p="http://www.springframework.org/schema/p"
    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-2.5.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-2.5.xsd
        http://www.directwebremoting.org/schema/spring-dwr
        http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
        default-lazy-init="true">
       
    <context:annotation-config />

 <!-- 对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
    <context:component-scan base-package="webapp.action"/>

    <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映?? -->
    <bean id="annotationMapper" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
    <!-- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> -->   


 <!--定义表现?? -->
 <bean id="viewResolver"
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="viewClass">
   <value>org.springframework.web.servlet.view.JstlView</value>
  </property>
  <property name="prefix">
   <value>/jsp/</value>
  </property>
  <property name="suffix">
   <value>.jsp</value>
  </property>
 </bean>

 <!-- 异样处理 -->
 <bean id="exceptionResolver"
  class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
  <property name="defaultErrorView">
   <value>/exception/error</value>
  </property>
 </bean>

 <!-- 语言更改拦截?? -->
 <bean id="localeChangeInterceptor"
  class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
  <property name="paramName" value="local" />
 </bean>

 <bean id="localeResolver"
  class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
  
 <!-- file upload resolver  -->
 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  <property name="maxUploadSize" value="10000000"></property>
 </bean> 

 <!--Request Mapping -->

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    </bean>
    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory"/>
 </bean>
 <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
  <property name="transactionManager" ref="transactionManager"/>
  <property name="transactionAttributes">
   <props>
    <prop key="persist*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="remove*">PROPAGATION_REQUIRED,-Exception</prop>
   </props>
  </property>
 </bean>
 
    </beans>

application.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:context="http://www.springframework.org/schema/context"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
 xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd
  http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd
  http://www.directwebremoting.org/schema/spring-dwr
     http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd"
 default-lazy-init="true">

 
 <bean id="dataSource"
 class="org.apache.commons.dbcp.BasicDataSource">
 <property name="driverClassName"
 value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
 </property>
 <property name="url" value="jdbc:sqlserver://localhost:1433;DatabaseName=test;SelectMethod=Cursor"></property>  
 <property name="username" value="sa"></property>
 <property name="password" value="sa"/>   
</bean>
 
 
  <bean id="userDao" class="dao.base.impl.UserDaoImpl">
   <property name="sessionFactory" ref="sessionFactory"/>
 </bean>
 <bean id="userService" parent="baseTransactionProxy">
 <property name="proxyTargetClass" value="true"/>
  <property name="target">
   <bean class="service.base.impl.UserServiceImpl">
    <property name="userDao" ref="userDao"/>
   </bean>
  </property>
 </bean>
 <!-- Hibernate-->
 <bean id="sessionFactory" lazy-init="true"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref local="dataSource" />
  </property>
  <property name="mappingLocations">
   <list>
    <value>classpath:dao/**/*.hbm.xml</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <!-- 数据库方言
     <prop key="hibernate.dialect">
     org.hibernate.dialect.Oracle9Dialect
     </prop>-->

    <prop key="hibernate.dialect">
     org.hibernate.dialect.SQLServerDialect
    </prop>

    <!-- hibernate将实体类的.hbm.xml自动生成数据库
     <prop key="hibernate.hbm2ddl.auto">
     update
     </prop>-->

    <!-- 显示sql语句 -->
    <prop key="hibernate.show_sql">true</prop>
    <!-- 批量操作 -->
    <prop key="hibernate.jdbc.batch_size">50</prop>
    <prop key="hibernate.jdbc.fetch_size">50</prop>
   </props>
  </property>
 </bean>

 <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
 </bean>
 <bean id="baseTransactionProxy"
  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
  abstract="true">
  <property name="transactionManager" ref="transactionManager" />
  <property name="transactionAttributes">
   <props>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="persist*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="remove*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="create*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="modify*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="update*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
    <prop key="cnew*">
     PROPAGATION_REQUIRES_NEW,-Exception
    </prop>

   </props>
  </property>
 </bean>

 

 </beans>

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <display-name>
 ZD</display-name>
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
  classpath:applicationContext.xml
  </param-value>
 </context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>


 <filter>
  <filter-name>encodingFilter</filter-name>
  <filter-class>
   org.springframework.web.filter.CharacterEncodingFilter
  </filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>GBK</param-value>
  </init-param>
  <init-param>
   <param-name>forceEncoding</param-name>
   <param-value>true</param-value>
  </init-param>
 </filter>


 <filter-mapping>
  <filter-name>encodingFilter</filter-name>
  <servlet-name>ZD</servlet-name>
 </filter-mapping>


<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener  </listener-class>
</listener>

<listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>


 <servlet>
  <servlet-name>wstudio-debugger-tomcat6</servlet-name>
  <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
  <init-param>
   <param-name>suppressSmap</param-name>
   <param-value>true</param-value>
  </init-param>
  <load-on-startup>3</load-on-startup>
 </servlet>

 


 <servlet>
  <servlet-name>zhangdan</servlet-name>
  <servlet-class>
   org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  <load-on-startup>2</load-on-startup>
 </servlet>


    <servlet-mapping>
  <servlet-name>wstudio-debugger-tomcat6</servlet-name>
  <url-pattern>*.jsp</url-pattern>
 </servlet-mapping>
 
 
 <servlet-mapping>
  <servlet-name>zhangdan</servlet-name>
  <url-pattern>*.do</url-pattern>
 </servlet-mapping>

 


   <session-config>
  <session-timeout>20</session-timeout>
    </session-config>

 <welcome-file-list>
  <welcome-file>/login.jsp</welcome-file>
 </welcome-file-list>

    <error-page>
  <error-code>404</error-code>
  <location>/login.jsp</location>
 </error-page> 

</web-app>

 

 

 

0 0