找回密码
 注册
搜索

:::Eclipse中struts+spring+Hibernate框架的搭建:::

郎心勾妃 2008-8-14 11:00 显示全部楼层 阅读模式 来自: LAN
Eclipse中Struts框架搭建,使用插件StrutsIDE、GEF、HtmlEditor
准备

这里用的是Struts插件StrutsIDE,同时还必须下载GEFHtmlEditor两个插件来辅助其使用 字串7
下载StrutsIDE

版本:StrutsIDE 2.0.4
下载地址: http://osdn.dl.sourceforge.jp/amateras/24130/tk.eclipse.plugin.struts_2.0.4.zip
字串1
下载HtmlEdito

版本:HtmlEditor 2.0.4
下载地址:http://keihanna.dl.sourceforge.jp/amateras/24128/tk.eclipse.plugin.htmleditor_2.0.4.zip
下载GEF 1
版本: GEF 3.2.1
下载地址: http://www.eclipse.org/downloads/download.php?file=/tools/gef/downloads/drops/R-3.2.1-200609211617/GEF-runtime-3.2.1.zip&url=http://download.actuatechina.com/eclipse/tools/gef/downloads/drops/R-3.2.1-200609211617/GEF-runtime-3.2.1.zip&mirror_id=385  


[ 本帖最后由 郎心勾妃 于 2008-8-26 23:56 编辑 ]
回复

使用道具 举报

大神点评42

 楼主| 郎心勾妃 2008-8-14 11:02 显示全部楼层 来自: LAN
安装
这里几个插件的安装就不再赘述了,都是解压后覆盖到plugins下或者覆盖到eclipse下,大家结合前面tomcat的例子举一反三。 字串3

配置
都无需配置
   字串9
测试
打开eclipse后,在FileàNewàOther后,如果发现多出了一个名为Amateras的项目,如下如所示,那么则说明插件基本安装成功。 字串8
Demo 字串3
接下来使用StrutsIDE编写一个简单的基于struts框架的web小程序
1.       首先建立一个Tomcat project,为其命名,设置工程存放位置(具体步骤请参考tomcat篇),如下图所示 字串1

2.       接下来往这个tomcat工程添加struts架构。对着firstStruts点击右键NewàOther,选择Amateras下的StrutsàAdd Struts Support,如下图所示: 字串3
字串2
3.       添加Struts框架后,会有选项框弹出,这里我们用它的默认设置,一路next即可,但是这里还是对几个选项作一些简单的解释,如下图所示:
回复 支持 反对

使用道具 举报

 楼主| 郎心勾妃 2008-8-14 11:05 显示全部楼层 来自: LAN
  4.       finish后,这时工程的目录下会被添加许多类包  
小贴士:这里.jar.tld等文件在日后开发中是不需要去关注的,因此我们可以把它们都隐藏掉,以还给我们一个干净的工作空间。我们可以点击workspace中最右侧的一个向下的三角,

,然后点击Filters,如下图:
  
然后在弹出的框中输入需要被过滤的文件后缀名,如下,ok后会发现文件结构又变干净了。  
5.双击WEB-INF下的struts-config.xml,出现下图,这里可以将struts的业务流程使用图形显示出来,比较直观。
5.       选中按钮,在空白区域绘制一个page项后,双击该项,进行设置,如下

在下方的properties框中也将/page1.jsp改名为/index.jsp,点击ok,这样在工程中就会自动生成一个名为index.jsp的文件。
6.       双击index.jsp
回复 支持 反对

使用道具 举报

 楼主| 郎心勾妃 2008-8-14 11:05 显示全部楼层 来自: LAN
进行页面的编写,如下,粗体字部分是我们需要自己编写的,这里我们往页面中添加了一个文本框(属性名为username)一个按钮,和一个/welcome.do的请求名,最后Save  
<%@pagecontentType="text/html; charset=GBK"%>  
<%@tagliburi="/tags/struts-bean"prefix="bean"%>
<%@tagliburi="/tags/struts-logic"prefix="logic"%>
<%@tagliburi="/tags/struts-html"prefix="html"%>
<%@taglib



[ 本帖最后由 郎心勾妃 于 2008-8-14 11:07 编辑 ]
回复 支持 反对

使用道具 举报

 楼主| 郎心勾妃 2008-8-14 11:09 显示全部楼层 来自: LAN
uri="/tags/struts-nested"prefix="nested"%>  
<html:html> 字串7
    <head>

       <metahttp-equiv="Content-Type"content="text/html; charset=GBK"/>

       <title></title> 字串5
    </head> 字串7
    <body>
       <html:formmethod="POST"action="/welcome.do">

           your name:<html:textproperty="username"></html:text>
回复 支持 反对

使用道具 举报

 楼主| 郎心勾妃 2008-8-14 11:14 显示全部楼层 来自: LAN
<html:submitvalue="ok"></html:submit>  
       </html:form>  
    </body> 字串6
</html:html>

7.          /WEB-INF/src下建立2packages,分别是com.wish.struts.formcom.wish.struts.action用来存放formbeanactionbean,如下图  
8.对com.wish.struts.form点击右键NewàOtheràAmaterasàStrutsàStruts ActionFrom,弹出选项框,如下,我们给这个formbean起名为UserFormok


回复 支持 反对

使用道具 举报

 楼主| 郎心勾妃 2008-8-14 11:15 显示全部楼层 来自: LAN
  
8.    此时在com.wish.struts.form下会产生一个UserForm.java,编写该类(设立一个username属性,建立其get set方法)
package com.wish.struts.form;
import org.apache.struts.action.ActionForm;
publicclass UserForm extends ActionForm { 字串5
    privatestaticfinallongserialVersionUID = 1L; 字串2
    private String username;
    public String getUsername() {
回复 支持 反对

使用道具 举报

 楼主| 郎心勾妃 2008-8-14 11:16 显示全部楼层 来自: LAN
returnusername;  
    }
    publicvoid setUsername(String username) {
        this.username = username; 字串8
    }
}
9.com.wish.struts.action点击右键NewàOtheràAmaterasàStrutsàStruts Action,弹出选项框,如下,我们给这个actionbean起名为WelcomActionok
  
9.    双击生成的WelcomeAction.java,编写该类重写execute
回复 支持 反对

使用道具 举报

 楼主| 郎心勾妃 2008-8-14 11:17 显示全部楼层 来自: LAN
方法,如下:  
package com.wish.struts.action;
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.wish.struts.form.UserForm;
publicclass WelcomeAction extends Action {  
    public ActionForward execute(ActionMapping mapping, 字串6
           ActionForm form,
           HttpServletRequest reuqest,
           HttpServletResponse response) throws Exception { 字串7
       //
回复 支持 反对

使用道具 举报

 楼主| 郎心勾妃 2008-8-14 12:12 显示全部楼层 来自: LAN
TODO Auto-generated method stub  
       UserForm userForm=(UserForm)form; 字串8
       reuqest.setAttribute("username", userForm.getUsername());
       return mapping.findForward("welcome");   
    }
}
10.在工程目录下再添加一个跳转后的页面,方法同index.jsp,编写其代码(粗体部分),功能就是显示index.jsp输入的用户名
<%@pagecontentType="text/html; charset=GBK"%> 字串8
<%@tagliburi="/tags/struts-bean"prefix="bean"%>
<html:html> 字串8
    <head>
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

  • 0 关注
  • 3 粉丝
  • 10 帖子
 

天健社区APP