站長資訊網(wǎng)
        最全最豐富的資訊網(wǎng)站

        jsp速成精華

        Servlet三個要素:
        1.必須繼承自HttpServlet
        2.必須實現(xiàn)doGet()或者doPost()
        3.必須在web.xml中配置Servlet
        <servlet>
        <servlet-name> </servlet-name>
        <servlet-class> </servlet-class>
        </servlet>
        <servlet-mapping>
        <servlet-name> </servlet-name>
        <url-pattern> </url-pattern>
        </servelt-mapping>

        HttpServeltRrequest:請求對象
        getParameter():獲得表單元素的值
        getAttribute():獲得request范圍中的屬性值
        setAttribute():設置reqeust范圍中的屬性值
        setCharacterEncoding():設置字符編碼

        HttpSerletResponse:相應對象
        sendRedirect():外部跳轉(zhuǎn)
        getWriter():獲得輸出流對象
        setContentType(“text/html; charset=utf-8”):設置相應內(nèi)容格式和編碼

        四種會話跟蹤方式:
        1.Session
        HttpSession session = request.getSession();
        session.setAttribute(“name”, “zhangsan”);
        session.setAttribute(“pwd”, “aaa”);
        String name = (String) session.getAttribute(“name”);

        2.cookie:
        //創(chuàng)建Cookie
        Cookie cookie = new Cookie(“name”, “zhangsan”);
        //設置Cookie的超時時間
        cookie.setMaxAge(24 * 60 * 60 *60);
        //把Cookie發(fā)送到客戶端
        response.addCookie(cookie);

        //得到客戶端發(fā)送的Cookie
        Cookie [] cookies = request.getCookies();
        for(int i=0; i <cookies.length; i++) {
          Cookie temp = cookies;
          String key = temp.getName();
          String value = temp.getValue();
        }

        3.隱藏表單域
        <input type=”hidden” name=”name” value=”zhangsan” />
        request.getParameter(“name”);

        4.Url重寫
        問號傳參
        LoginServlet?username=zhangsan&pwd=123
        String name = request.getParameter(“username”);
        String pwd =request.getPareameter(“pwd”);

        內(nèi)部跳轉(zhuǎn):
        LoginServlet
        request.getRequestDispatcher(“index.jsp”).forward(request, resposne);
        外部跳轉(zhuǎn):
        response.sendRedirect(“index.jsp”);
        內(nèi)部跳轉(zhuǎn)是一次請求和一次響應
        外部跳轉(zhuǎn)是兩次請求和兩次響應

        ServletContext:Servlet上下文對象
        它是一個公共區(qū)域,可以被所有的客戶端共享
        setAttribute():向公共區(qū)域里放入數(shù)據(jù)
        getAttribute():從公共區(qū)域里取數(shù)據(jù)

        二:
        三:三個標準范圍:request, session, ServletContext
          共同點:都有setAttribute(), getAttribute()
          區(qū)別:范圍不同,request < session < servletContext
        四:四種會話跟蹤方式
        五:服務器上的五大對象
          request, response, servlet, session, servletContext
         
        Jsp:Java Server Page
        頁面構(gòu)成:7種元素
        1.靜態(tài)內(nèi)容:html
        2.指令:page, include, taglib:
        <%@ 指令名 屬性1=”屬性值1″ 屬性2=”屬性值2″ %>
        3.表達式: <%=表達式 %>
        4.Scriptlet <% Java代碼 %>
        5.聲明: <%! %>:變量和方法
        6.動作: <jsp:動作名 屬性=”屬性值”> </jsp:動作名>
        7.注釋:
        客戶端看不到的: <%– –%>
        客戶端可以看到的: <!– –>

        Jsp的執(zhí)行過程:
        1.轉(zhuǎn)譯:Jsp—>Servlet
        2.編譯:Servlet—->.class
        3.執(zhí)行:.class
        第一次訪問jsp的時候響應速度較慢,后面請求時響應速度快

        腳本:
        表達式: <%= %>
        Scriptlet: <% %>
        聲明: <%! %>

        指令:
        page:language, import, errorPage, isErrorpage
        include:file
        taglib:uri:指定標簽庫描述符的路徑 prefix:指定標簽的前綴

        隱式對象:
        分類:
        1.輸入和輸出對象:request(HttpServletRequest),
                        response(HttpServletResponse),
                        out(JspWriter), servlet中的out是PrintWriter
        2.作用域通信對象:pageContext, request,
                        session(HttpSession),
                        application(ServletContext)
        3.Servlet對象:page(this), config
        4.錯誤對象:exception
           
        JavaBean:
        一個標準的JavaBean有三個條件
        1.共有的類
        2.具有不帶參數(shù)的公共的構(gòu)造方法
        3.具有set()和get()方法
        4.私有屬性

        Jsp中的標準動作:
        1.useBean:創(chuàng)建JavaBean的一個實例
        <jsp:useBean id=”stu” class=”com.westaccp.test.Student” scope=”page/session/application/request” />
        2.setProperty:給JavaBean的屬性賦值
        <jsp:setProperty name=”stu” property=”stuName” value=”zhangsan” />
        <jsp:setProperty name=”stu” property=”stuName” param=”txtName” />
        value和param不能同時使用
        偷懶的方法: <jsp:setProperty name=”stu” property=”*” />
        這個時候需要注意的是,表單元素的名字必須和JavaBean的屬性值
        一模一樣
        3.getProperty:獲得JvaBean的屬性值
        <jsp:getProperty name=”stu” property=”stuName” />
        4.forward:內(nèi)部跳轉(zhuǎn),相當于request.getRequestDispatcher().forward(request, response);
        <jsp:forward page=”index.jsp” />
        5.include:包含
        <jsp:include page=”header.jsp” flush=”true” />

        表達式語言:
        EL: Expression Language
        語法格式: ${表達式 }
        表示式 = 運算符 + 操作數(shù)
        運算符:跟Java比較,多了一個empty, 少了一個賦值運算符
        ${empty “”} : true
        ${empty null} :true
        操作數(shù):
        –>常量:布爾型(true/false), 整型, 浮點型, 字符串(可以用”, 還可以用””), Null
        –>變量:
            1.指的是放在四個標準范圍里的屬性(page, request, session, application)
            2.在編準范圍內(nèi)的搜索順序:page–>request—>session—>application
            3.怎么取得變量值:點運算符., 還以用[]
            <%
              request.setAttribute(“name”, “lisi”);
            %>
            ${requestScope.name}
            或者
            ${requestScope[“name”]}
        –>隱式對象
            1.pageContext:通過它可以訪問request, session, servletContext
            2.跟范圍由關(guān)的:pageScope, requestScope, sessionScope, applicationScope
            3.跟輸入有關(guān)的:param, paramValues
            4.其他的:header, cookie, headervalues,

        EL表達式適用的場合:
        1.可以在靜態(tài)文本中使用
        2.與自定義標簽結(jié)合使用
        3.和JavaBean結(jié)合使用
        <jsp:userBean id=”stu” class=”com.westaccp.test.Student” scope=”session” />
        <jsp:setProperty name=”stu” property=”stuName” value=”hello” />
        ${stu.stuName}

        自定義標簽:
        1.標簽處理程序?qū)崿F(xiàn)
        —>實現(xiàn):繼承自BodyTagSupport或者TagSupport
                  一般會重寫doStartTag(), doEndTag(), doAfterBody()
        —>描述:在標簽庫描述符文件中描述(.tld)
            <taglib>
              <tlib-version>1.0 </tlib-version>
              <jsp-version>2.0 </jsp-version>
              <short-name>simpletag </short-name>
           
              <tag>
                <name>showbody </name>
                <tag-class>com.westaccp.test.ShowBodyTag </tag-class>
                <body-content>empty/jsp </body-content>
                <attribute>
                <name>color </name>
                </attribute>
              </tag>
            </taglib>
        —>使用: <%@ taglib uri=”WEB-INF/mytag.tld” prefix=”my” %>
                  <my:showbody />
        2.標簽文件
        —>實現(xiàn)和描述
            在.tag文件中實現(xiàn)
            設置主體內(nèi)容: <%@ body-content=”empty/scriptless” %>
            設置屬性: <%@ attribute name=”name” required=”true” rtexprvalue=”true” %>
            有主體內(nèi)容: <jsp:doBody scope=”session” var=”theBody” />
            <%
                String body = (String) session.getAttribute(“theBody”);
            %>
        —>使用
            WEB-INF/tags/sayhello.tag
            <%@ taglib tagdir=”/WEB-INF/tags/” prefix=”you” %>
            <you:sayhello />
           
        標準標簽庫:
        1.核心標簽庫
        –>通用:
            set: <c:set var=”” value=”” scope=”” />
            out: <c:out value=”” />
            remove: <c:remove var=”” scope=”” />
        –>條件:
            if: <c:if test=””>….. </c:if>
            choose: <c:choose>
                    <c:when test=””>… </c:when>
                    <c:when test=””>… </c:when>
                    <c:when test=””>… </c:when>
                        …..
                        <c:otherwise>… </otherwise>         
                    </c:choose>
        –>迭代:
            forEach: <forEach var=”” items=”” varStatus=”” begin=”” end=””>
            foTokens: <foTodens var=”” items=”” delim=”,; |”> </foTodens>
            Java,C#;SQL |C
        2.I18N與格式化標簽庫
        –>setLocale:設置本地區(qū)域
        –>bundle:設置資源包
        –>setBundle:設置資源包
        –>message:輸出消息
        3.SQL標簽庫
        –>setDataSource:設置數(shù)據(jù)源,用于獲得與數(shù)據(jù)庫的連接
        –>query:執(zhí)行查詢
        –>update:執(zhí)行增,刪,改
        –>transaction:事務
        –>param:參數(shù)
        4.XML標簽庫

        過濾器:
        生命周期:
        1.實例華:
        2.初始化:init()
        3.過濾:doFilter()
        4.銷毀:destroy()
        5.不可用

        配置:
        <filter>
        <filter-name> </filter-name>
        <filter-class> </filter-class>
        </filter>
        <filter-mapping>
        <filter-name> </filter-name>
        <url-pattern> </url-pattern>
        </filter-mapping>

        幾個重要的接口:
        1.Filter:init(), doFilter(), destroy()
        2.FilterChain: doFilter(request, response)
        3.FilterConfig:getFilterName(), getInitParameter(),

        過濾器鏈:—>1—>2—>3—>Servlet 請求
                <—-1 <—2 <—3 <—        響應
               
        MvC設計模式
        1.ModelI:jsp+JavaBean
        2.ModelII:jsp+Servlet+JavaBean
                  jsp—view
                  servlet—control
                  javabean—model

        MVC:
        M–Model:模型:訪問后臺數(shù)據(jù)庫
        V–view:視圖:展示
        C–control:控制器:控制程序流程

        ModelII和MVC的關(guān)系:
        MVC是一種設計模式,ModelII它是MVC的一種具體的實現(xiàn)

        贊(0)
        分享到: 更多 (0)
        網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號
        主站蜘蛛池模板: 国产精品二区观看| 亚洲国产主播精品极品网红 | 一级A毛片免费观看久久精品| 国产精品91在线| 亚洲欧美精品一区久久中文字幕| 在线观看日韩精品| 精品乱码一区二区三区四区| 亚洲综合欧美精品一区二区| 久久精品国产亚洲7777| 99久久99久久精品国产| 国产精品视频网站你懂得| 国产女主播精品大秀系列| 亚洲国产精品无码中文字| 欧美日韩精品久久久免费观看| 尤物国产在线精品福利一区| 国产精品vⅰdeoxxxx国产| 人妻少妇精品中文字幕av蜜桃| 欧美精品一区二区三区免费观看| 国产精品 码ls字幕影视| 久久精品国产一区| 精品国产欧美另类一区| 999国内精品永久免费视频| 久久精品夜夜夜夜夜久久| 亚洲αv在线精品糸列| 亚洲欧美日韩国产成人精品影院| 亚洲国产精品成人网址天堂| 欧美久久亚洲精品| 久久夜色精品国产亚洲av| 精品国产污污免费网站入口| 国产欧美日韩综合精品一区二区三区 | 日韩精品毛片| 无码人妻精品一区二区蜜桃AV| 毛片a精品**国产| 免费精品精品国产欧美在线| 欧美亚洲成人精品| 亚洲一区无码精品色| 最新国产在线精品观看| 麻豆成人久久精品二区三区免费| 亚洲国产精品无码久久久秋霞2 | 国产vA免费精品高清在线观看| 国产精品igao视频|