• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

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整合基本结束!


 


 

 

 

posted @ 2013-08-27 19:05  Class Xman  阅读(259)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3