Java_SSH项目主要步骤记录

 建立Spring-Struts-Hibernate的步骤整理

1. 建立web project

2. 建立hernate, action, service

3. 右击项目,add myeclipse libraray, 加入struts2.1-core, hibernate3.3-core, spring3.1-core

4. 右击项目,myeclipse, add spring capability, web.xml中增加

5. Add hiernate capability,选择数据源,和存放生成实体类的hibernate包,

      选择existing配置文件,contextApplication.xml

6. 此时applicationContext.xml可能报错,找不到 org.apache.commons.dbcp.BasicDataSource和org.springframework.orm.hibernate3.LocalSessionFactoryBean 

解决:先除去配置文件中空行,若还是报错,向lib中加入commons-dbcp.jar, commons-pool.jar, spring.jar

7. 右击项目add struts capability, 选择struts2.*,拦截/*

8. 确保web.xml中含有如下配置

  <context-param> 

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

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

  </context-param> 

   <listener>

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

   </listener>

   <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>/*</url-pattern>

   </filter-mapping></web-app>

9. 将项目部署在tomcat或其他web server上,启动服务器。  

访问 http://localhost:8090/Java_SSH_R/  

若不报错,配置基本没问题。

10. 增加简单的逻辑进行测试

struts.xml中增加入口

<constant name="struts.objectFactory" value="spring"></constant> (重要)

<package name="base" extends="struts-default">

<action name="first" class="r" method="execute">

<result name="success">/index.jsp</result>

</action>

</package>

contextApplication.xml中进行相应配置

<bean id="r" class="action.RAction">

</bean>

action/RAction.java

package action;

import com.opensymphony.xwork2.ActionSupport;

public class RAction extends ActionSupport{

public String execute(){

return SUCCESS;

}

}


访问 http://localhost:8090/Java_SSH_R/first 

如果访问成功,则整个SSH整合基本结束!




  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值