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

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

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

    隨筆-21  評論-29  文章-0  trackbacks-0

    開始學習Struts了 小黑會把每一天學習的心得體會發到blogjava和大家一起分享 本人為嚴重菜鳥 肯請各位老鳥指教啦!
    開發環境:  Myeclipse6.0 + Tomcat5.5 + jdk1.6 + struts1.3
    學習資料: 傳智播客視頻教程 下載地址:http://www.verycd.com/topics/249195

     

     1.為什么使用struts?
            建立在MVC模式上
            開源項目
            與其他技術和框架具有很好的融合性
            大大提高了開發速度
    2. Framework概念
           人們用來解決相同或者相似類型問題的方案
            特點:可重用性、可擴展性、可伸縮性
            基于請求響應(Request-Response)模式的應用Framework的邏輯結構:
                    控制器(Controller)
                    業務邏輯層(Business Logic)
                    數據邏輯層(Data Logic)
    3.Struts的概念和體系結構
    Struts是Apache組織的一個開源項目。主要是采用Servlet和JSP技術來實現的。Struts是一個基于Sun Java EE平臺的MVC框架,它采用MVC模式,
    將MVC模式“分離顯示邏輯和業務邏輯”的能力發揮得淋漓盡致。網址:struts.apache.org
    Struts is a flexible control layer based on standard technologies like Java Servlets,JavaBeans,ResourceBundles,and XML, as well as various Jakarta Commons packages,
    Like BeanUtils and Chain of Responsibility. The framework helps you create an extensive development environment for your application,base on published  standards and proven design patterns.

    4.實踐步驟  搭建環境 建立ActionForm 建立Action 頁面訪問
      ① 搭建環境:
           導入jar包,使用其中相關的類
           建立一個配置文件:struts-config.xml    方便Struts用戶使用 一般放在WEB-INF下
                                                Web.xml 
           注冊struts中心控制器 ——ActionServlet
           注意事項: struts配置文件的位置 預先加載控制器

      ② 開發Form
            建一個類,繼承ActionForm
            注冊,修改配置文件struts-config.xml
      ③ 開發Action
            建立一個類,繼承Action
                   覆蓋execute方法
                   需要強制轉型
                   調用其他模塊
                   跳轉(根據關鍵字,關鍵字參照該action中forward標簽中的name屬性)
            注冊,修改配置文件struts-config.xml
       ④ 建立三個JSP文件 Login.jsp LoginSuccess.jsp LoginFailure.jsp

    5.操作過程
        1新建一web項目 
          

       2導入struts的jar包 我這里選擇導入全部jar包
          
           
        

      3在WB-INF下建立一個struts-config.xml文件
        

       編寫struts-config.xml代碼如下
     

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">

    <struts-config>
      
    <form-beans>
         
    <form-bean name="loginForm" type="cn.itcast.LoginForm"></form-bean>
      
    </form-beans>
      
    <action-mappings>
         
    <action path="/login" type="cn.itcast.LoginAction" name="loginForm">
             
    <forward name="loginSuccess" path="/LoginSuccess.jsp"></forward>
             
    <forward name="loginFailure" path="/LoginFailure.jsp"></forward>
         
    </action>
      
    </action-mappings>
    </struts-config>

    修改web.xml文件為如下代碼

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
        xmlns
    ="http://java.sun.com/xml/ns/javaee" 
        xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation
    ="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    >
        
        
    <servlet>
           
    <servlet-name>action</servlet-name>
           
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
           
    <init-param>
               
    <param-name>config</param-name>
               
    <param-value>/WEB-INF/struts-config.xml</param-value>
           
    </init-param>
           
    <load-on-startup>0</load-on-startup>
        
    </servlet>

        
    <servlet-mapping>
           
    <servlet-name>action</servlet-name>  
           
    <url-pattern>*.do</url-pattern>
        
    </servlet-mapping>



    </web-app>


    在src下新建兩個類 LoginForm和LoginAction 其中LoginAction繼承Action類 LoginForm繼承LoginAction類



    package cn.itcast;

    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;

    public class LoginAction extends Action {

        @Override
        
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                
    throws Exception {
            
              LoginForm loginForm 
    = (LoginForm) form ;
              
    if(loginForm.getUsername().equals("itcast")){
                  
    return mapping.findForward("loginSuccess");
              }

              
    else 
                  
    return mapping.findForward("loginFailure");
        }

         
    }




    package cn.itcast;

    import org.apache.struts.action.ActionForm;

    public class LoginForm extends ActionForm {
        
    /**
         * 
         
    */

        
    private static final long serialVersionUID = 1L;
        
    private String username = null ;
        
    private String password = null ;
        
    public String getUsername() {
            
    return username;
        }

        
    public void setUsername(String username) {
            
    this.username = username;
        }

        
    public String getPassword() {
            
    return password;
        }

        
    public void setPassword(String password) {
            
    this.password = password;
        }

        
        
        
        
    }


    在WebRoot下新建三個jsp文件 分別為Login.jsp  LoginSuccess.jsp   LoginFailure.jsp 



    login.jsp文件

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding
    ="ISO-8859-1"
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
        
    <form action="<%= request.getContextPath()%>/login.do" method="get">
           username:
    <input type="text" name="username"><br>
           password:
    <input type="password" name="password"><br>
           
    <input type="submit" value="login">
        
    </form>
    </body>
    </html>

    LoginSuccess.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding
    ="ISO-8859-1"
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
       Login Success!!!
    </body>
    </html>

    LoginFailure.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding
    ="ISO-8859-1"
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
        Login Failure!!!
    </body>
    </html>


    部署web應用 展示文件結構



    啟動tomcat 在瀏覽器中輸入http://localhost:8080/Strutsdemo/Login.jsp 展示效果如下








    無論如何 經過兩個小時的學習 終于運行出了我的第一個struts程序了
    希望繼續努力哦! 順祝大家51節日快樂

    posted on 2009-05-01 19:49 特立獨行 閱讀(479) 評論(0)  編輯  收藏 所屬分類: Struts框架
    主站蜘蛛池模板: 亚洲性色AV日韩在线观看| 久久精品a亚洲国产v高清不卡| 久久亚洲精品专区蓝色区| 99久久99久久免费精品小说| 亚洲视频在线视频| 久久免费精彩视频| 亚洲视频在线观看一区| 最近2022中文字幕免费视频| 中文字幕亚洲第一在线| 50岁老女人的毛片免费观看| 亚洲国产精品乱码在线观看97| 青青青国产在线观看免费网站 | 亚洲VA综合VA国产产VA中| 日本亚洲中午字幕乱码 | 国产亚洲精品无码成人| 东方aⅴ免费观看久久av| 婷婷亚洲久悠悠色悠在线播放| 51视频精品全部免费最新| 色偷偷女男人的天堂亚洲网| 日韩免费三级电影| eeuss影院ss奇兵免费com| 亚洲国产精品SSS在线观看AV| 亚洲a一级免费视频| 中文字幕乱码亚洲无线三区| 免费一级毛片在级播放| 中国毛片免费观看| 亚洲第一成年人网站| 性xxxx视频播放免费| 成人自慰女黄网站免费大全| 亚洲嫩模在线观看| 性感美女视频免费网站午夜 | 日韩中文字幕免费| 成人av片无码免费天天看| 亚洲精品日韩中文字幕久久久| 成年女人毛片免费播放视频m| 一级黄色免费毛片| 亚洲综合免费视频| 免费一级毛片一级毛片aa| 亚洲精品在线免费观看| 成人嫩草影院免费观看| 亚洲午夜一区二区电影院|