日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Jsp-Servlet 概要总结[转]

發(fā)布時(shí)間:2023/12/13 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Jsp-Servlet 概要总结[转] 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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[i];
????????? String key = temp.getName();
????????? String value = temp.getValue();
????? } 3.隱藏表單域
????? <input type="hidden" name="name" value="zhangsan" />
????? request.getParameter("name"); 4.Url重寫(問(wèn)號(hào)傳參)
????? LoginServlet?username=zhangsan&pwd=123
????? String name = request.getParameter("username");
????? String pwd =request.getPareameter("pwd");

內(nèi)部跳轉(zhuǎn): LoginServlet 內(nèi)部跳轉(zhuǎn)是一次請(qǐng)求和一次響應(yīng)
????? request.getRequestDispatcher("index.jsp").forward(request, resposne);
外部跳轉(zhuǎn): 外部跳轉(zhuǎn)是兩次請(qǐng)求和兩次響應(yīng)
????? response.sendRedirect("index.jsp");
ServletContext: Servlet上下文對(duì)象 它是一個(gè)公共區(qū)域,可以被所有的客戶端共享
setAttribute(): 向公共區(qū)域里放入數(shù)據(jù)
getAttribute(): 從公共區(qū)域里取數(shù)據(jù)


隱式對(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

EL: Expression Language
語(yǔ)法格式: ${表達(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:通過(guò)它可以訪問(wèn)request, session, servletContext
???? 2.跟范圍由關(guān)的:pageScope, requestScope, sessionScope, applicationScope
???? 3.跟輸入有關(guān)的:param, paramValues
???? 4.其他的:header, cookie, headervalues

EL表達(dá)式適用的場(chǎng)合:
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)簽庫(kù)描述符文件中描述(.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)簽庫(kù):
1.核心標(biāo)簽庫(kù)
-->通用:
????? 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與格式化標(biāo)簽庫(kù)
-->setLocale:設(shè)置本地區(qū)域
-->bundle:設(shè)置資源包
-->setBundle:設(shè)置資源包
-->message:輸出消息
3.SQL標(biāo)簽庫(kù)
-->setDataSource:設(shè)置數(shù)據(jù)源,用于獲得與數(shù)據(jù)庫(kù)的連接
-->query:執(zhí)行查詢
-->update:執(zhí)行增,刪,改
-->transaction:事務(wù)
-->param:參數(shù)
4.XML標(biāo)簽庫(kù)

過(guò)濾器:
生命周期:
????? 1.實(shí)例華:
????? 2.初始化:init()
????? 3.過(guò)濾: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(),
過(guò)濾器鏈:--->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:模型:訪問(wèn)后臺(tái)數(shù)據(jù)庫(kù)
V--view:視圖:展示
C--control:控制器:控制程序流程
ModelII和MVC的關(guān)系:
MVC是一種設(shè)計(jì)模式,ModelII它是MVC的一種具體的實(shí)現(xiàn)

轉(zhuǎn)載于:https://www.cnblogs.com/elina/archive/2009/08/03/1538033.html

總結(jié)

以上是生活随笔為你收集整理的Jsp-Servlet 概要总结[转]的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。