采用spring+structs+hibanate框架开发javaWeb项目

来源:互联网 发布:python入门教程pdf 编辑:程序博客网 时间:2024/05/16 13:59

项目目录是src,WebRoot以及一些库引用的目录,jre Library和j2ee library,WebRoot目录下是META-INF\MANIFEST.MF,和WEB-INF\web.xml 。WEB-INF下面还有classes,lib,其他的一些文件,默认的web项目,没有添加ssh的效果;

 

1、添加spring支持

在web项目名称上右键-〉myEclipse->add spring capabilities ,structs和hibernate都一样,如果你手动删除了,还可以在java build path的配置中心通过添加myeclipse library的方式添加上,通过右键的方式最为快捷

看项目中的变化:

项目中添加了spring 3.0 core libraries和spring 3.0 AOP libraries 可以在右键->Build Path->Remove Build path 或者config Build path 可以添加和移除引用库

 

 

当添加了structs 2.1之后,web.xml中添加了

<filter>
   <filter-name>struts2</filter-name>
   <filter-class>
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
   </filter-class>
  </filter>
  <filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>*.do</url-pattern>
  </filter-mapping>

 

添加hibernate的时候选择spring  configuration file(applicationContext.xml)

在applicationContext.xml中添加了

<bean id="dataSource"
  class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName"
   value="org.apache.derby.jdbc.ClientDriver">
  </property>
  <property name="url"
   value="jdbc:derby://localhost:1527/myeclipse">
  </property>
  <property name="username" value="classiccars"></property>
  <property name="password" value="myeclipse"></property>
 </bean>
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="dataSource" />
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.SQLServerDialect
    </prop>
   </props>
  </property>
 </bean>

 

在web.xml中添加

<context-param>

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

     <param-value>classpath:applicationContext.xml</param-value>

</context-param>

<listener>

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

</listener>

spring就ok了

0 0