中信初中高級(jí)備課部分se使用入門_第1頁(yè)
中信初中高級(jí)備課部分se使用入門_第2頁(yè)
中信初中高級(jí)備課部分se使用入門_第3頁(yè)
中信初中高級(jí)備課部分se使用入門_第4頁(yè)
中信初中高級(jí)備課部分se使用入門_第5頁(yè)
已閱讀5頁(yè),還剩9頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、1Servlet2l用 Java 編寫的服務(wù)器端程序l運(yùn)行在 Web 服務(wù)器上l執(zhí)行服務(wù)器端處理Web瀏覽器Web服務(wù)器HTTP 請(qǐng)求HTTP 響應(yīng)Servlet3請(qǐng)求請(qǐng)求 客戶端客戶端響應(yīng)響應(yīng)Servlet 運(yùn)行于服務(wù)器上lServlet 是一個(gè)用 Java 編寫的程序,此程序在服務(wù)器上運(yùn)行以處理客戶端請(qǐng)求4lServlet的優(yōu)點(diǎn): 持久 速度快且性能更佳 跨平臺(tái) 可擴(kuò)展 安全 可用于各種客戶端5ServletConfig 接口在初始化的過(guò)程中由 Servlet 容器使用ServletContext 接口定義 Servlet 用于獲取來(lái)自其容器的信息的方法 ServletRequest 接口

2、 向服務(wù)器請(qǐng)求信息 ServletResponse 接口 響應(yīng)客戶端請(qǐng)求qjavax.servlet 包的接口為:6l用來(lái)封裝web.xml中對(duì)當(dāng)前Servlet的配置信息lgetInitParameter()-可以獲取初始化參數(shù) Web.xmll l7l代表當(dāng)前Servlet運(yùn)行的上下文環(huán)境,Web容器會(huì)為每一個(gè)Web工程創(chuàng)建一個(gè)對(duì)應(yīng)ServletContext對(duì)象 setAttribute() getAttribute() removeAttribute()8l為Servlet所發(fā)送的請(qǐng)求,用ServletRequest封裝 setAttribute() getAttribute() re

3、moveAttribute() getParameter() 常用子接口HttpServletRequest9lServlet對(duì)客戶段所做的響應(yīng),用ServletResponse描述 getWriter():獲取PrintWriter輸出流給客戶發(fā)送的響應(yīng)內(nèi)容 setContentType:設(shè)置響應(yīng)內(nèi)容的響應(yīng)類型和字符集信息 sendRedirect:設(shè)置重新請(qǐng)求路徑 子接口HttpServletResponse10ServletInputStream 類用于從客戶端讀取二進(jìn)制數(shù)據(jù)ServletOutputStream 類用于將二進(jìn)制數(shù)據(jù)發(fā)送到客戶端q javax.servlet 包的類為:1

4、1HttpServletRequest 接口 提供 HTTP 請(qǐng)求信息HttpServletResponse 接口 提供 HTTP 響應(yīng)q javax.servlet.http 包的接口為: 12這是一個(gè)顯示 HttpServletRequest 和 HttpServetResponse 接口一些方法的簡(jiǎn)單 Servlet演示:示例 1import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class ClientServlet extends HttpServlet protected void d

5、oGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException response.setContentType(“text/html;charset=GBK”); PrintWriter out= response.getWriter(); out.println(“ 您好!”); 需要導(dǎo)入的包用于處理 GET 請(qǐng)求的方法創(chuàng)建設(shè)置文本格式和 PrintWriter 對(duì)象的方法以將數(shù)據(jù)發(fā)送給客戶端13 clientservlet chapter2.ClientS

6、ervletchapterhelloWorld clientservlet /clientservlet web.xml文件中配置Servlet14public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException response.setContentType(CONTENT_TYPE); response.setCharacterEncoding(GB2312); PrintWriter out = response.getWrite

7、r(); try String username = request.getParameter(username); String password = request.getParameter(password); if (username.equals() | password.equals() userInterface(response); else out.println(+username + 歡迎第一次使用歡迎第一次使用Servlet); out.println(今天的日期是:今天的日期是: + new Date(); catch(Exception e) userInterface(response); out.close(); public void userInterface(HttpServletResponse response)throws IOException PrintWriter out=response.getWriter(); out.println(); out.println(loginservlet); out.println(); out.println(歡迎第一次使用歡迎第一次使用Servlet); out.println(form method=post action=/ServletModule/loginservlet);

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論