<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增加學(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
    流程圖:


    實踐操作實現(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>


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


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






    建立IStudentDAO



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


    }

    新建兩個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)用 并訪問測試




    以上步驟實現(xiàn)了添加學(xué)生的基本功能,由于本機沒有安裝oracle數(shù)據(jù)庫,應(yīng)用數(shù)據(jù)庫實現(xiàn)模塊的設(shè)計以后再補充!
    posted on 2009-05-02 16:44 特立獨行 閱讀(354) 評論(0)  編輯  收藏 所屬分類: Struts框架
    主站蜘蛛池模板: 人人爽人人爽人人片av免费| 免费看片在线观看| 亚洲综合在线成人一区| 又粗又硬又黄又爽的免费视频| 免费观看成人久久网免费观看| 中国china体内裑精亚洲日本| 亚洲伊人久久精品影院| 毛片高清视频在线看免费观看| 两个人的视频www免费| 亚洲午夜无码久久久久小说| 久久久久久亚洲精品中文字幕| 国产一区二区三区在线免费观看| 18禁止看的免费污网站| h视频在线观看免费| 亚洲精品美女久久久久久久| 久久久亚洲欧洲日产国码二区| 亚洲精品麻豆av| 国内自产拍自a免费毛片| 中文字幕视频免费| 成人网站免费大全日韩国产| 狠狠躁狠狠爱免费视频无码| 春暖花开亚洲性无区一区二区| 亚洲一区在线视频| 亚洲日本精品一区二区| ZZIJZZIJ亚洲日本少妇JIZJIZ| 破了亲妺妺的处免费视频国产| 免费观看激色视频网站(性色)| 青娱乐免费在线视频| 91在线老王精品免费播放| 16女性下面无遮挡免费| 猫咪社区免费资源在线观看| 成人永久免费高清| 成人免费视频软件网站| 国产91免费在线观看| 中文字幕成人免费视频| 福利免费观看午夜体检区| 国产成人精品免费视频大| 四虎在线免费播放| 亚洲综合久久夜AV | 亚洲黄色片免费看| 亚洲第一区视频在线观看|