您的位置:首页 > 其它

J2EE环境搭建感悟

2015-11-21 11:26 309 查看
1、总体上先分层

a、src(默认的)b、config(配置文件)c、test(测试用)d、WebRoot下的css、images、js、pages、upload等。

2、加入框架

a、先加入spring支持。b、随后hibernate及struts支持

其中a中,spring框架加入后,首先,加入show_sql,format_sql。如

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">

org.hibernate.dialect.MySQLDialect

</prop>

<prop key="hibernate.show_sql">

true

</prop>

<prop key="hibernate.format_sql">

true

</prop>

</props>

</property>

其次、加入hibernate模板类。

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">

<property name="sessionFactory">

<ref bean="sessionFactory"/>

</property>

</bean>

3、加入公共页面如error.jsp等等。

4、为src分层如:dao,service,action,utils等级目录。又可以再分为前后端。

5、为config(配置文件)分层,包括hibernate,spring,struts等目录,在spring目录下加入例如applicationContext-transaction.xml等文件;在struts配置下加入struts.xml等文件;在hibernate文件下加入生成pojo的.hbm.xml类型文件;加入log4j。

6、web.xml中加入监听

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/classes/spring/applicationContext-*.xml</param-value>

</context-param>

<listener>

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

</listener>

7、导入数据库连接jar包

8、重启服务器,测试,如果看到控制台spring,hibernate,struts信息正常,没报错,证明环境搭建成功!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: