`
woaiwofengkuang
  • 浏览: 25732 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

一个电子商务项目的开发手记

阅读更多

最近要做一个电子商务系统,已经开始三周了。我最终选择的开发环境是:JDK1.5,Tomcat5.5.27,eclipse3.3+myclipse6.0,SqlServer200。采用SSH方案来进行开发。用的是struts1.3.8,spring2.0,hibernate3.1。

在以后我会将遇到的一些技术难点写出来与大家讨论的。

首先来说一下SSH的集成:

这三大柜架的集已经是老声长谈了,在这里就只是简单的说一下:

首先先将struts添加到项目中,再将Spring加入到项目中,最后将hibernate加入到项目中,在这里将hibernate配置文件中的内容全部在Spring的配置文件applicationContext.xml中进行配置。抱括jdbc,*.hbm.xml。要注意的是在这里我们不再需要Hibernate为我们生成SessionFactory了而是用Spring中的org.springframework.orm.hibernate3.LocalSessionFactoryBean来进行统一的管理。

下面我们将struts和Spring集合到一起,让spring来对action进行统一的管理

我们要在struts-config.xml中加入以下信息

<plug-in
        className="org.springframework.web.struts.ContextLoaderPlugIn">
        <set-property property="contextConfigLocation"
            value="/WEB-INF/classes/applicationContext.xml" />
 </plug-in>

在这里你的Spring的配置文件的路可以是相对也可以是绝对的,在这里我把它直接放在了src下,如果你将它放在WEB-INT下则可以这么写:

<plug-in
        className="org.springframework.web.struts.ContextLoaderPlugIn">
        <set-property property="contextConfigLocation"
            value="/WEB-INF/applicationContext.xml" />
 </plug-in>

再在struts-config.xml中入一个controller注要是为了让spring来能够自己找的到我们的action。写法为

<controller
        processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />

当我们在struts-context.xml中加入这个后我们便可以将我们的action配置信息中的type=""这一项去掉不用了。然后我们在applicationContext.xml中可以进行action的配置了。在这里要注意的是我们的action在applicationContext.xml配置时我们不要用id,而是改用name属性。这里的name要和我们在struts-config.xml中action的配置中的path=""属性相对应。不要忘记这个"/",也要加进去。如:

struts-config.xml中有一个action配置如下:

<action attribute="registerForm"
            input="/enter/hospital_register/register.jsp" name="registerForm"
            path="/hospital_register" scope="request">
            <forward name="success" path="enter/member/success.jsp" />
 </action>

则我们在applicationContex.xml中可以这样配置

<bean name="/hospital_register" type="action所在的包.action类名">

<为所依赖的接口>

</bean>

当然在里也可以将这个controller去掉不要而是将action的配置信息中的type="action类位置"改为type="org.springframework.web.struts.DelegatingActionProxy"即可。

0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics