web项目开发开发一般流程:
1) 实地考察调研----编写调研文档
2)需求分析----编写需求分析文档
3)设计阶段(概要设计,详细设计)----编写设计文档
4)编码阶段
5)测试----指定测试计划,测试用例,编写测试报告
6)运行和维护
web项目开发环境准备:
1)创建一个web项目,编码为utf8
2)创建一个数据库,编码为utf8
create database oa default character set utf8;----创建数据库create user oa identified by '1234';-----创建用户
grant all on oa.* to itcastoa;-----为用户授权
3)导入struts2相关jar包(12个)
4)在web.xml中配置struts2的前端控制器
<!-- 配置struts2的前端控制器 --><filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
5)在config下提供struts.xml
<struts><constant name="struts.devMode" value="true" />
<!-- 将对象工厂指定为spring -->
<constant name="struts.objectFactory" value="spring"/>
<!-- struts的Action访问后缀 -->
<constant name="struts.action.extension" value="do"/>
</struts>
6)导入spring相关jar包
7)在web.xml中配置spring
<!-- 通过上下文参数指定spring配置文件的位置 --><context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<!-- 配置spring的上下文载入器监听器 ,项目启动时加载spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
8)在config下提供spring的配置文件beans.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: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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 读取属性文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driverClass}"></property>
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="initialPoolSize" value="${initialPoolSize}"></property>
<property name="minPoolSize" value="${minPoolSize}"></property>
<property name="maxPoolSize" value="${maxPoolSize}"></property>
</bean>
<!-- 本地会话工厂bean -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 注入hibernate属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<!-- hibernate映射文件的位置 -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:cn/itcast/oa/domain</value>
</list>
</property>
</bean>
<!-- Hibernate事务管理器 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 对注解提供支持 -->
<context:annotation-config/>
<!-- 组件扫描 -->
<context:component-scan base-package="cn.itcast.oa"/>
<!-- 注解驱动 -->
<tx:annotation-driven transaction-manager="txManager"/>
</beans>
9)在config下提供log4j.properties
10 在config下提供jdbc.properties
driverClass=com.mysql.jdbc.DriverjdbcUrl=jdbc:mysql://localhost:3306/itcast_oa
user=itcastoa
password=1234
initialPoolSize=20
minPoolSize=20
maxPoolSize=40