- 相關(guān)推薦
計算機二級考試WEB備考知識點(diǎn)
計算機科學(xué)是一門(mén)包含各種各樣與計算和信息處理相關(guān)主題的系統學(xué)科,從抽象的算法分析、形式化語(yǔ)法等等,到更具體的主題如編程語(yǔ)言、程序設計、軟件和硬件等。下面是小編收集的計算機二級考試WEB備考知識點(diǎn),希望大家認真閱讀!
ServletGenericServletHttpServlet關(guān)系
javax.servlet.GenericServlet實(shí)現了Servlet接口
javax.servlet.http.HttpServlet繼承自javax.servlet.GenericServlet類(lèi)
所以編寫(xiě)Servlet繼承HttpServlet或GenericServlet即可。
如何編寫(xiě)自定義的Servlet代碼
1、追加環(huán)境變量servlet-api.jar,編寫(xiě)自定義servlet繼承HttpServlet,并重寫(xiě)doGet方法,生成class文件待用(訪(fǎng)問(wèn)控制符應該是public)
2、在webapps目錄下找到example中的WEB-INF,copy其中的web.xml
3.在webapps目錄下生成自己的文件夾,copyWEB-INF/web.xml
如何部署Servlet(web.xml)、ServletUrl映射路徑(注意*的使用)
servlet
!--servlet的名字,隨便起個(gè)名,但和下面的servlet-name名一致--
servlet-namemgc/servlet-name
!--WEB-INF中文件路徑--
servlet-classAnyDirectory.ServletClassName/servlet-class
!--或者可以用servletclass:jsp-file/WEB-INF/hello.jsp/jsp-file--
/servlet
servlet-mapping
!--servlet的名字,隨便起個(gè)名,但和上面的servlet-name名一致--
servlet-namemgc/servlet-name
!--訪(fǎng)問(wèn)映射路徑--
url-pattern/hello/url-pattern
/servlet-mapping
Servlet生命周期:
類(lèi)加載、實(shí)例化、初始化、服務(wù)、銷(xiāo)毀
service(HttpServletRequestrequest,HttpServletResponseresponse)方法的作用:
根據不同的請求,進(jìn)行分發(fā)工作(Http協(xié)議)
init(ServletConfigconfig)與init()方法
當容器(tomcat)幫忙調用init(ServletConfigconfig)并且給傳過(guò)來(lái)一個(gè)參數config,這個(gè)方法把參數對象的引用指向類(lèi)的成員變量this.config,并且調用類(lèi)的this.init()方法。如果我們在寫(xiě)Servlet類(lèi)時(shí)只要重寫(xiě)init(ServletConfigconfig)就可以了,但是init()不就成了多余的了嗎?實(shí)際上init()方法是為了防止程序員在寫(xiě)Servlet類(lèi)重寫(xiě)init(ServletConfigconfig)時(shí)忘記寫(xiě)super.init(ServletConfigconfig),這樣就容易造成出現空指針異常。而這就要求我們最好不要重寫(xiě)init(ServletConfigconfig)。
配置Servlet初始化參數:
init-paramparam-nameparam-value
ServletContext上下文是什么?和Servlet、ServletConfig的關(guān)系
ServletContext:
servletContext接口是Servlet中最大的一個(gè)接口,呈現了web應用的Servlet視圖。ServletContext實(shí)例是通過(guò)getServletContext()方法獲得的,由于HttpServlet繼承Servlet的關(guān)系GenericServlet類(lèi)和HttpServlet類(lèi)同時(shí)具有該方法。
【計算機二級考試WEB備考知識點(diǎn)】相關(guān)文章:
9月計算機二級web考試試題及答案10-30
2016最新計算機二級考試備考習題及答案09-29
2016年計算機二級考試備考指南10-25
計算機二級MSOffice考試知識點(diǎn)積累09-20
計算機二級考試ACCESS常見(jiàn)知識點(diǎn)10-19
計算機二級JAVA考試常見(jiàn)知識點(diǎn)05-30
計算機二級MSOffice考試重要知識點(diǎn)08-26
如何備考計算機二級?06-23