Myeclipse开发struts+hibernate+spring新手入门---环境配置----项目开发示例 Myeclipse开发struts+hibernate+spring小记 开发前准备工作: 1、下载eclipse3.1版本 下载地址: 2、下载Myeclipse插件 下载地址: 3、根据需要下载所需要的数据库驱动。 部分下载地址: 4、下载的eclipse3.1进行解压缩。安装Myeclipse,分为手工安装和自动安装两种安装方法。 具体安装方法如下: 手工安装: 自动安装: 5、安装完成后。启动Myeclipse。 准备开发工作: 步骤: 1、新建项目: New>projects后进入下图 本文主要介绍开发Web Project项目,因此需要选择Web Project,下一步,进入下图: Project Name:为需要建立的项目名称。填写好项目名称后,Finish。新建项目完成。本文在项目命名为test.。 项目建立完成之后,在Myeclipse视图中,Package Explorer中显示如下: test:为项目名称。 Src:为源文件所放路径。 WebRoot:为Web root folder 2、加载Struts 在所建立项目test上右键后,提示如下页面: 在弹出的菜单中,根据图例提示,选择Myeclipse后在弹出的二级菜单中选择Add Struts Capabilities…后提示如下图所示: 在弹出的对话框中,设置如下: Struts config path:默认,一般不需要改变。 Struts specification:选择Struts版本,在此项目中,选择Struts 1.2版本。 Base Package for new classes:设置为空。 取消Install Struts TLDs选项。 其他默认: Finish.后在Package Explorer的Lib包如下: 到此,加载Struts完成。在此需要关注Struts-config.xml文件。 3、加载hibernate: 同加载struts方式类似,选择Myeclipse后在弹出的二级菜单中选择Add Hibernate Capabilities…后提示如下图所示: 可以根据提示,选择Hibernate Specification:本项目选择Hibernate3,其他默认,Next> 默认后直接下一步。在此可以去掉Configuration File Name中的内容。Next> 后去掉下一级页面的Create SessionFactory class选项。然后Finish,Finish完成后,在Lib目录下会提示相关的jar包。 4、加载spring in action in action 同加载struts方式类似,选择Myeclipse后在弹出的二级菜单中选择Add spring in action in action Capabilities…后提示如下图所示: 选择所需要的spring in action in action包,然后默认下一步,直到完成。 到此,Struts+hibernate+spring配置完成。 附加:在项目名称的右键后进入Properties然后进入Java Build Path后查看加载的jar包。 具体项目的开发详细文档请见下一篇文章《struts+hibernate+spring项目开发示例》 Myeclipse平台struts+hibernate+spring项目开发示例 接:Myeclipse开发struts+hibernate+spring新手入门---环境配置 如果您按照上篇文章配置成功,可以进行开发简单的J2EE项目。 开发前准备: 1、新建项目包:如下图: Dao:数据层;service:逻辑层;web:web展现层。 2、建立好三层架构,部署好包名。建立一个jsp文件,取名为:login.jsp 代码如下: <% @ taglib uri = " http://struts.apache.org/tags-bean " prefix = " bean " %> <% @ taglib uri = " http://struts.apache.org/tags-html " prefix = " html " %> <% @ taglib uri = " http://struts.apache.org/tags-logic " prefix = " logic " %> <% @ taglib uri = " http://struts.apache.org/tags-tiles " prefix = " tiles " %> < HTML > < HEAD > < TITLE > test < TITLE > < HEAD > < BODY > < html:form action = " /login " method = " post " > 用户名: < html:text property = " username " size = " 15 " /> < br > 密 码: < html:password property = " password " size = " 15 " />< br > < html:submit property = " submit1 " style = " FONT-WEIGHT:bold;COLOR:red " > 登 录 < html:submit > < html:form > < BODY > < HTML > 3、配置struts-config.xml文件;建立action、formbean; 改配置可以自动生成,使用eclipse进行自动生成,在建立时,如下图,可直接生成对应的action类和formbean类。 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> 3 4 <struts-config> 5 <data-sources /> 6 <form-beans> 7 <form-bean name="LoginForm" type="com.test.web.form.LoginForm" /> 8 9 </form-beans> 10 11 <global-exceptions /> 12 <global-forwards /> 13 <action-mappings> 14 <action attribute="LoginForm" input="/login.jsp" name="LoginForm" path="LoginAction" scope="request" type="com.test.web.action.LoginAction" validate="true"> 15 <forward name="faile" path="faile.jsp" /> 16 <forward name="success" path="success.jsp" /> 17 </action> 18 19 </action-mappings> 20 21 <message-resources parameter="ApplicationResources" /> 22 </struts-config> 对应生成的formbean如下代码所示: 1 import javax.servlet.http.HttpServletRequest; 2 import org.apache.struts.action.ActionErrors; 3 import org.apache.struts.action.ActionForm; 4 import org.apache.struts.action.ActionMapping; 5 6 /** 7 * MyEclipse Struts 8 * Creation date: 11-10-2005 9 * 10 * XDoclet definition: 11 * @struts.form name="LoginForm" 12 */ 13 public class LoginForm extends ActionForm { 14 15 /** password property */ 16 private String password; 17 18 /** username property */ 19 private String username; 20 21 22 /** 23 * Method validate 24 * @param mapping 【Struts】 Struts 是一个基于 MVC(Model-View-Controller)设计模式的开源框架,用于构建企业级 Java Web 应用程序。在Myeclipse中,通过Add Struts Capabilities功能,可以快速地在项目中集成Struts。配置过程中,Struts-config.xml文件是核心,它包含了应用的配置信息,如Action映射、Form Bean定义等。配置Struts时,需要注意Struts specification的选择,例如在示例中选择了Struts 1.2版本。 【Hibernate】 Hibernate 是一个对象关系映射(ORM)框架,它允许开发者将Java对象与数据库表进行映射,简化了数据库操作。在Myeclipse中,通过Add Hibernate Capabilities来添加Hibernate支持。配置时,可以选择Hibernate版本(如Hibernate 3),并配置相关配置文件,但可以取消Create SessionFactory class选项,避免自动生成SessionFactory类。完成后,Lib目录下会包含必要的Hibernate库。 【Spring】 Spring 是一个全面的Java企业级应用开发框架,提供了依赖注入(DI)、面向切面编程(AOP)、事务管理等功能。在Myeclipse中,添加Spring支持类似Struts和Hibernate,通过Add spring in action in action Capabilities。选择所需的Spring库,完成配置后,项目将包含Spring的核心库。 【Myeclipse】 Myeclipse 是一个集成开发环境,它是Eclipse的扩展,尤其适合Java EE项目的开发。Myeclipse 提供了丰富的向导和工具,使得配置Struts、Hibernate和Spring变得简单。在项目中,可以通过右键选择Properties,进入Java Build Path检查已添加的jar包,确保所有必要的库都已导入。 【项目开发流程】 1. 创建项目:选择Web Project类型,设置项目名称,如test。 2. 建立项目结构:创建Dao、Service和Web三层架构,分别存放数据访问、业务逻辑和Web展示层代码。 3. 创建JSP页面:例如login.jsp,使用Struts标签库编写用户登录界面。 4. 配置Struts-config.xml:定义Action和Form Bean,配置转发规则。 5. 生成Action和Form Bean:利用Myeclipse自动生成对应的Action类和Form Bean,简化编码工作。 【总结】 在Myeclipse中开发基于Struts、Hibernate和Spring的项目,首先需要正确配置这三个框架的环境,包括安装Myeclipse、下载相关插件和数据库驱动,然后在项目中添加Struts、Hibernate和Spring的支持。接着,根据项目需求创建合适的目录结构,编写前端页面(如JSP),配置核心配置文件(如Struts-config.xml),并自动生成或手动编写Action和Form Bean类。确保所有必要的库都已导入,即可开始具体的业务逻辑实现和数据库操作。这样的项目结构有利于实现松耦合和模块化,提高代码的可维护性和可扩展性。
![text/html](https://img-home.csdnimg.cn/images/20210720083451.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/octet-stream](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/release/download_crawler_static/1664632/bg1.jpg)
![](https://csdnimg.cn/release/download_crawler_static/1664632/bg2.jpg)
![](https://csdnimg.cn/release/download_crawler_static/1664632/bg3.jpg)
剩余13页未读,继续阅读
![avatar](https://profile-avatar.csdnimg.cn/0f0ce53df8dc4378ba30f682dc0aa168_wsedwsed.jpg!1)
- 粉丝: 9
- 资源: 111
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- C# winform置托盘图标并闪烁演示源码.zip
- 打包和分发Rust工具.pdf
- SQL中的CREATE LOGFILE GROUP 语句.pdf
- C语言-leetcode题解之第172题阶乘后的零.zip
- C语言-leetcode题解之第171题Excel列表序号.zip
- C语言-leetcode题解之第169题多数元素.zip
- ocr-图像识别资源ocr-图像识别资源
- 图像识别:基于Resnet50 + VGG16模型融合的人体细胞癌症分类模型实现-图像识别资源
- C语言-leetcode题解之第168题Excel列表名称.zip
- C语言-leetcode题解之第167题两数之和II-输入有序数组.zip
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
- 1
- 2
- 3
- 4
前往页