<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    cc

    隨筆 - 20, 文章 - 0, 評論 - 1, 引用 - 0
    數據加載中……

    Eclipse開發struts完全指南

    Eclipse開發struts完全指南
    來 源:賽迪網 作者:Junsan
    一、準備安裝程序

    1、JDK 5.0 安裝程序下載

    下載地址:
    
    https://jsecom15b.sun.com/ECom/EComActionServlet
    /DownloadPage:~:com.sun.
    sunit.sdlc.content.DownloadPageInfo;
    jsessionid=502E87C71D77E3BC297C08B35
    DAC9AD4;jsessionid=502E87C71D77E3BC297C08B35DAC9AD4



    同意協議后,可以下載jdk-1_5_0_05-windows-i586-p.exe。

    2、tomcat 5.5.9下載

    下載地址:http://jakarta.apache.org/site/downloads/downloads_tomcat-5.cgi

    最新版本是5.5.11alpha版,由于是測試版,所以,可能存在不確定的因素,所以,我們這里下載5.5.9 exe。

    3、Sysdeo Eclipse Tomcat Launcher plugin 3.1beta版下載

    下載地址:http://www.sysdeo.com/eclipse/tomcatplugin

    這里下載tomcatPluginV31beta.zip。

    4、eclipse 3.1安裝程序下載

    下載地址:http://www.eclipse.org/downloads/index.php

    這里需要對應版本的JDT,如果下載的是Eclipse SDK版本就自帶了,如果沒有,同一個下載頁面的靠后部分有JDT的下載鏈接,下載后將對應的文件分別拷貝進eclipse安裝目錄下的對應的文件夾即可。

    這里我們下載eclipse-SDK-3.1-win32.zip 。

    5、GEF 3.1 安裝程序下載

    下載地址:

    http://download.eclipse.org/tools/gef/downloads/drops/R-3.1-200507071758/

    index.php

    這里我們下載GEF-ALL-3.1.zip。

    6、Eclipse HTML Editor 1.6.7 安裝程序下載

    下載地址:https://sourceforge.jp/projects/amateras/files/?release_id=16537

    #16537

    這里我們下載:tk.eclipse.plugin.htmleditor_1.6.7.zip。

    7、StrutsIDE 1.1.7 安裝程序下載

    下載地址:https://sourceforge.jp/projects/amateras/files/?release_id=16537#16537

    這里我們下載:tk.eclipse.plugin.struts_1.1.7.zip。

    好了,到此我們準備好了所有的安裝包。

    二、安裝JDK并配置開發環境?

    這里只需要雙擊JDK安裝包的exe文件,按照提示安裝即可。安裝完成后,將JDK安裝目錄下的bin文件夾設置進環境變量的path路徑中去。同時,將JRE的lib目錄下的rt.jar包設置進環境變量的classpath中去。?

    這里我們把JDK安裝到了默認安裝路徑C:\Program Files\Java\jdk1.5.0_02下。這里就不多說了,網上可以搜索到很多JDK安裝配置的文章。?

    三、安裝tomcat服務器?

    只需要雙擊tomcat安裝包的exe文件,按照提示安裝即可,這里我們的安裝目錄為D:\Tomcat5.5,管理員密碼設置為12345678。?

    四、安裝Eclipse開發工具?

    只需要把eclipse-SDK-3.1-win32.zip安裝包解壓,然后把里面的eclipse文件夾剪切至想放置的目錄即可,這里我們把eclipse安裝到了D:\eclipse目錄下。?

    在安裝目錄下雙擊eclipse.exe文件,即可啟動eclipse。中間會詢問默認的工作目錄,你可以按其默認設定的,也可以自己設定工作目錄,這里設置為E:\workspace目錄。請選中Use this as the default and do not ask again選項,這樣以后啟動就不會再詢問了。?

    到此eclipse安裝成功。?

    五、安裝tomcatPlugin插件?

    安裝很簡單,解壓我們已經下載的安裝包tomcatPluginV31beta.zip,將解壓后的com.sysdeo.eclipse.tomcat_3.1.0.beta文件夾拷貝至D:\eclipse\plugins目錄下即可。我們關掉已經打開的eclipse,重新打開,OK,現在我們會發現工具欄上多了幾個雄貓的圖標,就是tomcat的啟動、停止和重啟動的按鈕。打開eclipse的window/preferences,我們在左邊的樹種也可以找到tomcat一項。?

    點擊tomcat項,在右邊我們選擇version 5.x版本,然后設定tomcat home為D:\Tomcat5.5,Contexts directory為D:\Tomcat5.5\conf\Catalina\localhost。到此tomcat plugin設置完畢。?

    六、安裝GEF插件?

    同樣,將GEF-ALL-3.1.zip解壓縮,然后拷貝解壓后的eclipse目錄下的三個文件夾到D:\eclipse目錄下,覆蓋所有的現有文件夾。?

    好了,到此GEF安裝完成。

    七、安裝Eclipse HTML Editor插件

    解壓縮tk.eclipse.plugin.htmleditor_1.6.7.zip包,然后將plugins目錄拷貝至D:\eclipse目錄下覆蓋原文件夾即可。到此Eclipse HTML Editor插件安裝完成。

    八、安裝StrutsIDE插件

    解壓縮tk.eclipse.plugin.struts_1.1.7.zip包,然后將plugins目錄拷貝至D:\eclipse目錄下覆蓋原文件夾即可。

    好了,到此StrutsIDE插件安裝完成。

    6、創建action對象

    同創建form的過程相同,我們只是新建一個com.is.action包,同樣的過程,打開新建向導,只是選擇Struts Action,創建LoginAction.java類,均選默認值。我們編輯LoginAction為如下內容:

    
    package com.is.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.is.form.LoginForm; 
    
    public class LoginAction extends Action 
    { 
    private static final long serialVersionUID = 1L; 
    
    public ActionForward execute
    (ActionMapping mapping, 
    ActionForm form, 
    HttpServletRequest request,
    HttpServletResponse response) 
    throws Exception { 
    
    // this line is here for when the
    input page is upload-utf8.jsp, 
    
    // it sets the correct character
    encoding for the response 
    
    String encoding = request.getCharacterEncoding(); 
    
    if ((encoding != null) && 
    (encoding.equalsIgnoreCase("GB2312")))
    { 
    
    response.setContentType
    ("text/html; charset=GB2312"); 
    
    } else { 
    
    response.setContentType
    ("text/html; charset=GBK"); 
    
    } 
    
    try { 
    
    if (form instanceof LoginForm) 
    { 
    
    LoginForm theForm = (LoginForm) form; 
    
    if(theForm.getUsername().equals("user") && 
    
    theForm.getPassword().equals("123456")) 
    { 
    
    return new ActionForward("/welcome.do?type=true"); 
    
    } 
    
    
    else {                           
    
    return new ActionForward("/welcome.do?type=false"); 
    
    } 
    
    } 
    } catch (Exception e) 
    { 
    
    } 
    
    // this shouldn't happen in this example 
    
    return null; 
    			  
    			 } 
    }



    注意這里是直接用ActionForward轉向的,你也可以按照struts中提供的空白例程struts-blank.war中的做法進行轉向,可以比較一下會有收獲的。

    7、創建登錄成功頁面

    同創建index.jsp頁面相同,我們創建welcome.jsp頁面,均使用默認設置。并編輯其內容如下:

    <%@page pageEncoding="GBK" 
    contentType="text/html; 
    charset=GBK" %>
    <html> 
    <head> 
    <meta http-equiv="Content-Type" 
    content="text/html;
    charset=GBK"/> 
    <title></title> 
    </head> 
    <body> 
    <% 
    String type = request.getParameter("type"); 
    if(type!=null&&type.equals("true")){ 
    out.print("歡迎您的光臨!"); 
    
    } 
    else{ 
    out.print("對不起,你輸入的用戶名或者密碼錯誤!"); 
    } 
    %> 
    </body> 
    </html>



    8、增加Struts-config.xml中的配置

    添加formbean的配置,在 標簽之間加入:

    <form-bean 
    name="loginForm" 
    type="com.is.form.LoginForm"/>



    添加jsp文件的映射,在 標簽之間加入:

    <action 
    path="/index" 
    forward="/index.jsp"/> 
    <action 
    path="/welcome" 
    forward="/welcome.jsp"/>



    添加action文件的映射,在 標簽之間加入:

    
    path="/logincheck" 
    type="com.is.action.LoginAction" 
    name="loginForm" 
    scope="request" 
    validate="true"/>





    修改后的struts-config.xml大致如下形式:

    
    <?xml version="1.0"?> 
    <!DOCTYPE struts-config PUBLIC "-
    //Apache Software Foundation
    //DTD Struts Configuration 1.2//EN"
    "http://struts.apache.org/dtds
    /struts-config_1_2.dtd"> 
    <struts-config> 
    <data-sources> 
    </data-sources> 
    <form-beans> 
    <form-bean 
    name="loginForm" 
    type="com.is.form.LoginForm"/> 
    </form-beans> 
    <global-exceptions> 
    </global-exceptions> 
    <global-forwards> 
    </global-forwards> 
    <action-mappings> 
    <action 
    path="/index" 
    forward="/index.jsp"/> 
    <action 
    path="/welcome" 
    forward="/welcome.jsp"/>    
    <action 
    path="/logincheck" 
    type="com.is.action.LoginAction" 
    name="loginForm" 
    scope="request" 
    validate="true"/> 
    </action-mappings> 
     <controller processorClass=
     "org.apache.struts.tiles.TilesRequestProcessor"/> 
    <message-resources parameter="MessageResources"/> 
    <plug-in className=
    "org.apache.struts.tiles.TilesPlugin"> 
    <set-property property="definitions-config" 
    value="/WEB-INF/tiles-defs.xml"/> 
    <set-property property="moduleAware" value="true"/> 
    </plug-in> 
    <plug-in className=
    "org.apache.struts.validator.ValidatorPlugIn"> 
    <set-property property="pathnames"
    value="/WEB-INF/validator-rules.xml,
    /WEB-INF/validation.xml"/> 
    </plug-in> 
    </struts-config>



    到此我們可以運行測試程序了。

    9、運行測試程序

    右鍵點擊testweb工程根目錄,點擊菜單中的Tomcate project->update context definition,將工程部署進tomcat,成功后會提示操作成功。

    點擊菜單欄中的雄貓圖標啟動tomcat,然后在IE地址欄中輸入http://localhost:8080/testweb/index.do,我們會看到index.jsp的頁面內容。

    九、創建測試工程

    如果已經完成了上面所有步驟,現在可以重新啟動eclipse,使新安裝的插件生效,開始正式開發了。

    1、使用Sysdeo Tomcat Plugin創建tomcat工程:

    File->new->others,打開新建向導對話框,在樹中找到java->tomcat projects,選中,點擊next按鈕。在projects name中輸入textweb,選中Use default,點擊next。在下一個對話頁面,保持默認設置,點擊finished。這時,我們在eclipse的package explorer中會看到新建的工程testweb,創建完成。

    2、加入struts框架

    File->new->others,打開新建向導對話框,找到Amateras->Struts->Add Struts Support,選中點擊next按鈕。

    保持默認設置,點擊Finish按鈕。這時,在eclipse的package explorer中會看到增加了很多struts的庫文件,在WEB-INF下也增加了很多struts的配置文件。到此我們已經在項目加入了Struts框架。

    3、編輯struts-config.xml文件

    在WEB-INF文件夾下可以找到,右鍵點擊菜單中選擇open with->Amateras XML Editer可以直接對xml文本進行編輯,選擇open with->struts-config.xml editor可以在圖形模式下對文件進行編輯。

    在右邊的outline中點擊相應的struts對象可以添加新的對象進去。這里我們只是說明這里有一個比較方便的struts-config.xml文件的編輯器,后面我們將開發一個簡單的小程序。

    4、新建一個頁面index.jsp

    File->new->others,打開新建向導對話框,找到Amateras->JSP File,點擊next按鈕,FileName改為index.jsp,點擊Finish。然后打開index.jsp文件進行編輯,內容如下:

    <%@page pageEncoding="GBK"
    contentType="text/html; 
    charset=gb2312" %>
    <html>
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; 
    charset=gb2312"/>
    <title></title>
    </head>
    <body>
    <form name="form1" method="post" 
    action="/testweb/logincheck.do">
    <table width="300"  border="0"
    cellspacing="0" cellpadding="0">
    <tr align="center">
    <td colspan="2">用戶登錄信息</td>
    </tr>
    <tr>
    <td>用戶名</td>
    <td>
    <input name="username" 
    type="text" id="username"
    size="12">
    user    
    </td>
    </tr>
    <tr>
    <td>用戶密碼</td>
    <td>
    <input name="password" 
    type="text" id="password" 
    size="12">
    123456    
    </td>
    </tr>
    <tr align="center">
    <td colspan="2"><input 
    type="submit" name="Submit" 
    value="提交"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    5、創建form數據對象

    打開File->new->package對話框,name中輸入com.is.form,點擊Finish按鈕。在右邊的Package Explorer樹中找到剛才創建的包,右鍵點擊com.is.form包,菜單中的new->others,找到Amateras->struts->Struts Action Form,點擊next,在對話框中name欄輸入LoginForm,點擊Finish按鈕。

    編輯LoginForm類的內容為:

    
    package com.is.form;
    import org.apache.struts.action.ActionForm;
    public class LoginForm extends ActionForm 
    {
    private static final long 
    serialVersionUID = 1L;
    private String username = "";
    private String password = "";
    /**
    * @return Returns the password.
    */
    public String getPassword()
    {
    return password;
    }
    
     /**
    
    * @param password The password to set.
    */
    public void setPassword(String password)
    {
     this.password = password;
    }
    /**
    * @return Returns the username.
    */
    public String getUsername() 
    {
    return username;
    }
    /**
    * @param username The username to set.
    */
    public void setUsername(String username) 
    {
    this.username = username;
    }
    }

    注意,這里的兩個屬性分別對應我們jsp中form中的兩個輸入控件的名稱,為什么這樣做,可以去看struts的幫助文檔了,我就不詳細說了,還有form類再寫完屬性后,get和set方法可以通過eclipse的source中的命令來自動生成,在右鍵菜單中,也不詳細說了,去網上查資料吧,關于eclipse的使用有很多的文檔。

    posted on 2006-09-10 21:11 cc 閱讀(288) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 国产精品亚洲精品| 亚洲乱码一二三四五六区| 免费无码婬片aaa直播表情| 高清国语自产拍免费视频国产| 亚洲最大中文字幕无码网站| 人成午夜免费视频在线观看| 国产精品亚洲专区在线观看| 嫩草影院免费观看| 国产亚洲福利精品一区二区| 高清在线亚洲精品国产二区| jizz在线免费观看| 亚洲av无码片在线播放| 亚洲一区免费观看| 亚洲人成电影网站| 香蕉高清免费永久在线视频| 女人裸身j部免费视频无遮挡| 91麻豆精品国产自产在线观看亚洲| 色www永久免费网站| 日产亚洲一区二区三区| 青青草a免费线观a| 国产亚洲蜜芽精品久久| 国产亚洲一区二区三区在线不卡| 久久成人免费播放网站| 亚洲日本久久一区二区va| 日韩成人在线免费视频| 国产精品无码永久免费888| 亚洲视频在线视频| 国产精品另类激情久久久免费| 免费一区二区三区在线视频 | 亚洲AV无码国产一区二区三区| 国产国产成年年人免费看片| jizz18免费视频| 亚洲理论片在线中文字幕| 凹凸精品视频分类国产品免费| 中文日本免费高清| 亚洲AV无码成人专区| 久久国产成人精品国产成人亚洲| 亚洲黄色免费在线观看| 国产亚洲综合视频| 亚洲成人在线免费观看| 国产成人精品亚洲精品|