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

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

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

    BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
      37 Posts :: 64 Stories :: 21 Comments :: 0 Trackbacks

    Servlet三個(gè)要素:

    1.必須繼承自HttpServlet

    2.必須實(shí)現(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:請(qǐng)求對(duì)象
    getParameter():獲得表單元素的值
    getAttribute():獲得request范圍中的屬性值
    setAttribute():設(shè)置reqeust范圍中的屬性值
    setCharacterEncoding():設(shè)置字符編碼
    HttpSerletResponse:相應(yīng)對(duì)象
    sendRedirect():外部跳轉(zhuǎn)
    getWriter():獲得輸出流對(duì)象
    setContentType("text/html; charset=utf-8"):設(shè)置相應(yīng)內(nèi)容格式和編碼

    四種會(huì)話跟蹤方式:
    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");
    //設(shè)置Cookie的超時(shí)時(shí)間
    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重寫
    問號(hào)傳參
    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)是一次請(qǐng)求和一次響應(yīng)
    外部跳轉(zhuǎn)是兩次請(qǐng)求和兩次響應(yīng)
    ServletContext:Servlet上下文對(duì)象
    它是一個(gè)公共區(qū)域,可以被所有的客戶端共享
    setAttribute():向公共區(qū)域里放入數(shù)據(jù)
    getAttribute():從公共區(qū)域里取數(shù)據(jù)
    二:
    三:三個(gè)標(biāo)準(zhǔn)范圍:request, session, ServletContext
       共同點(diǎn):都有setAttribute(), getAttribute()
       區(qū)別:范圍不同,request  < session  < servletContext
    四:四種會(huì)話跟蹤方式
    五:服務(wù)器上的五大對(duì)象
       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.表達(dá)式: <%=表達(dá)式 %>
    4.Scriptlet <% Java代碼 %>
    5.聲明: <%! %>:變量和方法
    6.動(dòng)作: <jsp:動(dòng)作名 屬性="屬性值"> </jsp:動(dòng)作名>
    7.注釋:
    客戶端看不到的: <%-- --%>
    客戶端可以看到的: <!-- -->

    Jsp的執(zhí)行過程:
    1.轉(zhuǎn)譯:Jsp--->Servlet
    2.編譯:Servlet---->.class
    3.執(zhí)行:.class
    第一次訪問jsp的時(shí)候響應(yīng)速度較慢,后面請(qǐng)求時(shí)響應(yīng)速度快
    腳本:
    表達(dá)式: <%= %>
    Scriptlet: <% %>
    聲明: <%! %>
    指令:
    page:language, import, errorPage, isErrorpage
    include:file
    taglib:uri:指定標(biāo)簽庫描述符的路徑 prefix:指定標(biāo)簽的前綴
    隱式對(duì)象:
    分類:
    1.輸入和輸出對(duì)象:request(HttpServletRequest),
                     response(HttpServletResponse),
                     out(JspWriter), servlet中的out是PrintWriter
    2.作用域通信對(duì)象:pageContext, request,
                     session(HttpSession),
                     application(ServletContext)
    3.Servlet對(duì)象:page(this), config
    4.錯(cuò)誤對(duì)象:exception
       
    JavaBean:
    一個(gè)標(biāo)準(zhǔn)的JavaBean有三個(gè)條件
    1.共有的類
    2.具有不帶參數(shù)的公共的構(gòu)造方法
    3.具有set()和get()方法
    4.私有屬性
    Jsp中的標(biāo)準(zhǔn)動(dòng)作:
    1.useBean:創(chuàng)建JavaBean的一個(gè)實(shí)例
    <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不能同時(shí)使用
    偷懶的方法: <jsp:setProperty name="stu" property="*" />
    這個(gè)時(shí)候需要注意的是,表單元素的名字必須和JavaBean的屬性值
    一模一樣
    3.getProperty:獲得JvaBean的屬性值
    <jsp:getProperty name="stu" property="stuName" />
    4.forward:內(nèi)部跳轉(zhuǎn),相當(dāng)于request.getRequestDispatcher().forward(request, response);
    <jsp:forward page="index.jsp" />
    5.include:包含
    <jsp:include page="header.jsp" flush="true" />
    表達(dá)式語言:
    EL: Expression Language
    語法格式: ${表達(dá)式 }
    表示式 = 運(yùn)算符 + 操作數(shù)
    運(yùn)算符:跟Java比較,多了一個(gè)empty, 少了一個(gè)賦值運(yùn)算符
    ${empty ""} : true
    ${empty null} :true
    操作數(shù):
    -->常量:布爾型(true/false), 整型, 浮點(diǎn)型, 字符串(可以用'', 還可以用""), Null
    -->變量:
        1.指的是放在四個(gè)標(biāo)準(zhǔn)范圍里的屬性(page, request, session, application)
        2.在編準(zhǔn)范圍內(nèi)的搜索順序:page-->request--->session--->application
        3.怎么取得變量值:點(diǎn)運(yùn)算符., 還以用[]
         <%
          request.setAttribute("name", "lisi");
        %>
        ${requestScope.name}
        或者
        ${requestScope["name"]}
    -->隱式對(duì)象
        1.pageContext:通過它可以訪問request, session, servletContext
        2.跟范圍由關(guān)的:pageScope, requestScope, sessionScope, applicationScope
        3.跟輸入有關(guān)的:param, paramValues
        4.其他的:header, cookie, headervalues,
    EL表達(dá)式適用的場合:
    1.可以在靜態(tài)文本中使用
    2.與自定義標(biāo)簽結(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}
    自定義標(biāo)簽:
    1.標(biāo)簽處理程序?qū)崿F(xiàn)
    --->實(shí)現(xiàn):繼承自BodyTagSupport或者TagSupport
              一般會(huì)重寫doStartTag(), doEndTag(), doAfterBody()
    --->描述:在標(biāo)簽庫描述符文件中描述(.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.標(biāo)簽文件
    --->實(shí)現(xiàn)和描述
         在.tag文件中實(shí)現(xiàn)
         設(shè)置主體內(nèi)容: <%@ body-content="empty/scriptless" %>
         設(shè)置屬性: <%@ 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 />
        
    標(biāo)準(zhǔn)標(biāo)簽庫:
    1.核心標(biāo)簽庫
    -->通用:
         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 &brvbarC
    2.I18N與格式化標(biāo)簽庫
    -->setLocale:設(shè)置本地區(qū)域
    -->bundle:設(shè)置資源包
    -->setBundle:設(shè)置資源包
    -->message:輸出消息
    3.SQL標(biāo)簽庫
    -->setDataSource:設(shè)置數(shù)據(jù)源,用于獲得與數(shù)據(jù)庫的連接
    -->query:執(zhí)行查詢
    -->update:執(zhí)行增,刪,改
    -->transaction:事務(wù)
    -->param:參數(shù)
    4.XML標(biāo)簽庫
    過濾器:
    生命周期:
    1.實(shí)例華:
    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>
    幾個(gè)重要的接口:
    1.Filter:init(), doFilter(), destroy()
    2.FilterChain: doFilter(request, response)
    3.FilterConfig:getFilterName(), getInitParameter(),
    過濾器鏈:--->1--->2--->3--->Servlet 請(qǐng)求
             <----1 <---2 <---3 <---        響應(yīng)
           
    MvC設(shè)計(jì)模式
    1.ModelI:jsp+JavaBean
    2.ModelII:jsp+Servlet+JavaBean
              jsp---view
              servlet---control
              javabean---model
    MVC:
    M--Model:模型:訪問后臺(tái)數(shù)據(jù)庫
    V--view:視圖:展示
    C--control:控制器:控制程序流程
    ModelII和MVC的關(guān)系:
    MVC是一種設(shè)計(jì)模式,ModelII它是MVC的一種具體的實(shí)現(xiàn) 

    posted on 2009-08-20 15:26 xiachang88 閱讀(114) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产在线国偷精品免费看| 免费精品国自产拍在线播放 | 亚洲国产精品国自产拍AV| 日韩在线观看视频免费| 亚洲成?Ⅴ人在线观看无码| 青娱乐在线视频免费观看| 亚洲精品456播放| 久久久久久久久久免免费精品| 国产精品亚洲二区在线观看| 久久成人永久免费播放| 久久99国产亚洲高清观看首页| 久久久久久国产精品免费免费男同| 亚洲国产精品久久| 真人做人试看60分钟免费视频| 精品丝袜国产自在线拍亚洲| 女人被男人桶得好爽免费视频| 蜜臀亚洲AV无码精品国产午夜.| 亚洲国产精品嫩草影院久久| 中文字幕免费在线看线人动作大片 | 国产亚洲av片在线观看播放| 精品一卡2卡三卡4卡免费视频| 亚洲视频在线观看| 女人18毛片a级毛片免费| 九九全国免费视频| 亚洲福利视频一区| 成年美女黄网站18禁免费| 免费人成网上在线观看| 亚洲精品福利视频| 日本免费中文字幕在线看| 皇色在线免费视频| 亚洲人成电影青青在线播放| 国产在线观看免费视频播放器| 热久久这里是精品6免费观看| 亚洲剧情在线观看| 亚洲精品网站在线观看不卡无广告| 久9热免费精品视频在线观看| 最新亚洲春色Av无码专区| 国产日韩亚洲大尺度高清| 啦啦啦中文在线观看电视剧免费版 | 91久久精品国产免费一区| 亚洲成av人片在www鸭子|