<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增加學生
    分析: ①Struts環境
                  ②AddStudentForm(extends ActionForm)
                        sId,sname, major,  birth,  score
                         <form-bean name="addStudentForm" type="cn.itcast.AddStudentForm">
                        </form-bean>
                  ③AddStudentAction(extends Action)
                        覆蓋execute
                        <action path="/addStudentAction" type="cn.itcast.AddStudentAction" name="addStudentForm">
                            <forward name="addStudentSuccess" path="/addStudentSuccess.jsp">
                            <forward name="addStudentFailure" path="/addStudent.jsp">
                        </action>


                      IStudentDAO,StudentDAO
                      addStudent(AddStudentForm  form)
                   ④JSP: addStudent.jsp     addStudentSuccess
    流程圖:


    實踐操作實現過程
     先建AddStudentForm,其繼承自ActionForm類


    可參看Struts API 參考ActionForm的相關信息

    AddStudentForm類的代碼為 (注意使用source里面的Generate Getters and Setters)
    package cn.itcast;

    import org.apache.struts.action.ActionForm;

    public class AddStudentForm extends ActionForm {

        
    private static final long serialVersionUID = 1L;
        
    private String sname = null ;
        
    private String major = null ;
        
    private String score = null ;
        
    private java.sql.Date birth = null ;
        
    public String getSname() {
            
    return sname;
        }

        
    public void setSname(String sname) {
            
    this.sname = sname;
        }

        
    public String getMajor() {
            
    return major;
        }

        
    public void setMajor(String major) {
            
    this.major = major;
        }

        
    public String getScore() {
            
    return score;
        }

        
    public void setScore(String score) {
            
    this.score = score;
        }

        
    public java.sql.Date getBirth() {
            
    return birth;
        }

        
    public void setBirth(java.sql.Date birth) {
            
    this.birth = birth;
        }

    }

    在struts-config.xml中添加<form-bean name="addStudentForm" type="cn.itcast.AddStudentForm"></form-bean>


    新建一個AddStudentAction類,其繼承Action類


    AddStudentAction類覆蓋execute方法 并在struts-config.xml中加入action標簽 如下所示






    建立IStudentDAO



    新建StudentDAO,使其實現IStudentDAO接口 并把StudentDAO返回值改為true



    編寫AddStudentAction類代碼 如下
    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 AddStudentAction extends Action {
        @Override
        
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                
    throws Exception {        
            
              
    //1.cast the form to its subclass
                AddStudentForm addStudentForm = (AddStudentForm) form ;
                
              
    //2.invoke the IStudentDAO module
                IStudentDAO studentDAO = new StudentDAO();
                
    boolean successful = false ;
                successful 
    = studentDAO.addStudent(addStudentForm);
                
              
    //3.forward to next module by the result of the business logic
                String returnURLKeyWord = "addStudentFailure";
                
    if(successful == true){
                    returnURLKeyWord 
    = "addStudentSuccess";
                }

                
                
    return mapping.findForward(returnURLKeyWord);
        }


    }

    新建兩個JSP頁面 AddStudent.jsp  和 AddStudentSuccess.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()%>/addStudentAction.do" method="get">
           sname:
    <input type="text" name="sname"><br>
           major:
    <input type="text" name="major"><br>
           birth:
    <input type="text" name="birth"><br>
           score:
    <input type="text" name="score"><br>
           
    <input type="submit" value="add">
        
    </form>
    </body>
    </html>
    <%@ 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>
       Succeed in adding a student!!!
    </body>
    </html>
    部署應用 并訪問測試




    以上步驟實現了添加學生的基本功能,由于本機沒有安裝oracle數據庫,應用數據庫實現模塊的設計以后再補充!
    posted on 2009-05-02 16:44 特立獨行 閱讀(365) 評論(0)  編輯  收藏 所屬分類: Struts框架
    主站蜘蛛池模板: 亚洲无线电影官网| 亚洲一区无码中文字幕乱码| 亚洲精品国产高清嫩草影院| 在线亚洲午夜理论AV大片| 久久精品国产亚洲av水果派| 久久久久亚洲精品无码网址色欲| 久久av免费天堂小草播放| 青青草免费在线视频| 国产午夜亚洲精品理论片不卡| 亚洲冬月枫中文字幕在线看 | 精品无码国产污污污免费网站 | 亚洲视频一区二区三区四区| fc2免费人成在线| 国产1024精品视频专区免费| 亚洲视频在线精品| 亚洲色一区二区三区四区| 三年片在线观看免费观看大全一 | 91亚洲性爱在线视频| 国产精品美女午夜爽爽爽免费| 亚洲精品午夜国产va久久| 久久大香香蕉国产免费网站| 亚洲免费一区二区| 成人免费区一区二区三区| 国产小视频在线免费| 亚洲免费视频网址| 国产免费啪嗒啪嗒视频看看 | 美女免费视频一区二区三区| 最近高清中文字幕无吗免费看| 国产亚洲AV夜间福利香蕉149 | 亚洲国产一区二区a毛片| 99久久久国产精品免费蜜臀| 中文字幕亚洲乱码熟女一区二区 | 欧洲乱码伦视频免费| 亚洲美免无码中文字幕在线| 久久青草免费91线频观看站街| 亚洲一卡二卡三卡| 亚洲精品国产精品国自产观看| 24小时在线免费视频| 亚洲va久久久噜噜噜久久 | 亚洲人成电影网站| www国产亚洲精品久久久|