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

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

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

    隨筆-21  評(píng)論-29  文章-0  trackbacks-0
    模塊: 使用Struts增加學(xué)生
    分析: ①Struts環(huán)境
                  ②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
    流程圖:


    實(shí)踐操作實(shí)現(xiàn)過程
     先建AddStudentForm,其繼承自ActionForm類


    可參看Struts API 參考ActionForm的相關(guān)信息

    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>


    新建一個(gè)AddStudentAction類,其繼承Action類


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






    建立IStudentDAO



    新建StudentDAO,使其實(shí)現(xiàn)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);
        }


    }

    新建兩個(gè)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>
    部署應(yīng)用 并訪問測(cè)試




    以上步驟實(shí)現(xiàn)了添加學(xué)生的基本功能,由于本機(jī)沒有安裝oracle數(shù)據(jù)庫,應(yīng)用數(shù)據(jù)庫實(shí)現(xiàn)模塊的設(shè)計(jì)以后再補(bǔ)充!
    posted on 2009-05-02 16:44 特立獨(dú)行 閱讀(354) 評(píng)論(0)  編輯  收藏 所屬分類: Struts框架
    主站蜘蛛池模板: A片在线免费观看| 黄色免费在线网址| 中文在线日本免费永久18近| 国产大片91精品免费观看男同| 成人亚洲国产va天堂| 欧亚精品一区三区免费| 久久亚洲AV成人无码国产| 67pao强力打造高清免费| 久久久无码精品亚洲日韩蜜臀浪潮| 免费视频成人手机在线观看网址| 日本亚洲视频在线| 久久精品视频免费看| 亚洲精品中文字幕乱码| 999国内精品永久免费视频| 亚洲人xxx日本人18| 四虎成人精品在永久免费| 青青草97国产精品免费观看| 丁香五月亚洲综合深深爱| 国产精品免费观看调教网| 亚洲成a人片7777| 毛片大全免费观看| 无遮挡呻吟娇喘视频免费播放| AV在线亚洲男人的天堂| 一级毛片免费观看不卡的| 亚洲乱码卡三乱码新区| 免费国产不卡午夜福在线| 一区视频免费观看| 亚洲AV本道一区二区三区四区| 国产在线观看麻豆91精品免费| 亚洲一卡一卡二新区无人区| 免费人成网站7777视频| 国产成人免费AV在线播放 | 香蕉97碰碰视频免费| 亚洲毛片不卡av在线播放一区| 永久免费av无码网站yy| 亚洲av无码片区一区二区三区| 免费人成网站在线高清| 久久精品成人免费看| 精品亚洲456在线播放| 亚洲精品无码av天堂| 16女性下面无遮挡免费|