版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
responseservice()response對象可以完成對客戶端的response==載時,那么可以使用response.getOutputStream()。response.getOutputStream()IllegalStateException異UTF-8編碼的!UTF-8來解讀響應(yīng)content-type頭來解讀響應(yīng)數(shù)據(jù)。8KBhtmlutf-8response的utf-8response.setCharaceterEncoding(“utf-8”);; 8")當(dāng)你 時,你會發(fā)現(xiàn)瀏覽器地址欄中的URL會變成 200302表示重定向。所以完成重定向的第一步就是設(shè)置302。URL,所以完成重Location頭,指定第二個請求的URL地址。publicpublicclassAServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOExceptionresponse.setHeader("Location",}}上面代碼的作用是:當(dāng)AServlet后,會通知瀏覽器重定向到傳智主頁。客戶端瀏覽器解析publicpublicclassAServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{ }}publicclassAServletextendsHttpServletpublicvoidpublicclassAServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{ }}重定向的URL地址為:重定向就不要再使用response.getWriter()response.getOutputStream()requestServlet.service()service()service()request對象來獲封裝了請求正文數(shù)據(jù),如果是GETrequest是一個域?qū)ο?,可以把它?dāng)成MaprequestrequestJavaWebServletContext就是域?qū)ο?,它在整個ServletContext對象。request其中一個,request可以在一個請求中共享數(shù)據(jù)。requestServletServlet就么會覆蓋上一次的值,這一特性與Map相同;ObjectgetAttribute(Stringname)request中的數(shù)據(jù),當(dāng)前在獲取之前需要先去才行,例如:StringvalueString)request.getAttribute(“xxx”);xxx的域?qū)傩?;voidremoveAttribute(Stringname)requestname指定的域URL相關(guān)的方法。東西在中很有用;StringgetCharacterEncoding()setCharacterEncoding(),那么返回nullISO-8859-1編碼;POST請求中的參數(shù)有效! StringBuffergetRequestURL():返回請求URL路徑,例如:,System.System.out.println("request.getContentLength():"+System.out.println("request.getContentType():"+request.getContentType());System.out.println("request.getContextPath():"+request.getContextPath());System.out.println("request.getMethod():"+request.getMethod());System.out.println("request.getLocale():"+request.getLocale());System.out.println("request.getQueryString():"+request.getQueryString());System.out.println("request.getRequestURI():"+request.getRequestURI());System.out.println("request.getRequestURL():"+request.getRequestURL());System.out.println("request.getServletPath():"+request.getServletPath());System.out.println("request.getRemoteAddr():"+request.getRemoteAddr());System.out.println("request.getRemoteHost():"+request.getRemoteHost());System.out.println("request.getRemotePort():"+request.getRemotePort());System.out.println("request.getScheme():"+request.getScheme());System.out.println("request.getServerName():"+request.getServerName());System.out.println("request.getServerPort():"+Stringip=request.getRemoteAddr();if(ip.equals("")){Stringip=request.getRemoteAddr();if(ip.equals("")){response.getWriter().print("您的IP已 }else}超:一定是GET請求GETPOSTGET1KPOST<form<form o/ParamServlet"參數(shù)1:<inputtype="text參數(shù)2:<inputtype="text<inputtype="submitvalue="提交<a 下面是使用requestpublicpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{Stringv1=request.getParameter("p1");Stringv2=request.getParameter("p2");System.out.println("p1="+v1);System.out.println("p2="+v2);}publicpublicvoiddoPost(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{Stringv1=request.getParameter("p1");Stringv2=request.getParameter("p2");System.out.println("p1="+v1);System.out.println("p2="+v2);}publicvoiddoGet(HttpServletRequestrequest,publicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOExceptionString[]names=request.getParameterValues("name");}<a參數(shù)1:<input參數(shù)1:<inputtype="text參數(shù)2:<inputtype="text<inputtype="submitvalue="提交o/ParamServlet"<formpublicvoiddoPost(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{Enumerationnames=request.getParameterNames();while(names.hasMoreElements()){ }}Map<String,String[]> p=for(Stringname:par p.keySet()){String[]values=par System.outMap<String,String[]> p=for(Stringname:par p.keySet()){String[]values=par System.out.println(name+":"+}p2:[v2,p1:[v1,ServletServlet1來處Servlet1Servlet2來繼續(xù)處理這個請求。AServletpublicclassAServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{RequestDispatcherrd=request.getRequestDispatcher("/BServlet");rd.forward(request,response);}}publicclassBServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{}}publicclassBServletextendspublicclassBServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsepublicclassAServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{RequestDispatcherrd=request.getRequestDispatcher("/BServlet");rd.include(request,response);}}}}throwsServletException,IOExceptionresponse.getWriter()response.getOutputStream()向客戶端輸出,這一工作應(yīng)該由BServlet來完成;如果是使用請求包含,那么沒有這個限制;ServletJSPAServletBServletGETPOST,重定向的第二個請求一定是超ClassClassLoader絕對路徑:<a客戶端路徑:<a絕對路徑:<a客戶端路徑:<a相對路徑:<a <form <inputtype="submitvalue="表單<form <inputtype="submitvalue="表單<form<input<inputtype="submitvalue="表單2和表單2:以“/”開頭,相對主機,與當(dāng)前a.html的主機相同,即最終的頁面為;33:不以“/a.html所有路徑,即最終的路徑為:;publicclasspublicclassAServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{ }}假設(shè)AServlet的路徑為:publicclassAServletextendsHttpServletpublicclassAServletextendsHttpServletpublicrequest,throwsServletException,IOException}}假設(shè)AServlet的路徑為:<formaction="/<a 改,這一點確實是個問題。這一問題的處理方案會在學(xué)習(xí)了JSP之后講解! response.sendRedirect(request.getContextPath()+ 題的處理方案是使response.sendRedirect(request.getContextPath()+publicclassAServletextendspublicclassAServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{}}假設(shè)AServlet的路徑為:publicclassAServletextendsHttpServletpublicclassAServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOException{}}假設(shè)AServlet的路徑為:publicclassAServletextendsHttpServletpublicvoiddoGet(HttpServletRequestpublicclassAServletextendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponsethrowsServletException,IOExceptionStringpath1=this.getServletContext().getRealPath("a.txt");Stringpath2=this.getServletContext().getRealPath("/a.txt");}}path1path2是相同的結(jié)果:Classpackage;importpublicpackage;importpublicclassDemopublicvoidfun1()InputStreamin=}publicvoidfun2()InputStreamin=}} 類在 ClassLoaderpublicclassDemopublicvoidpublicclassDemopublicvoidfun1(){InputStreamin=}publicvoidfun2(){InputStreamin=}} ,即 ::<!DOCTYPE<!DOCTYPE<metahttp-equiv="content-type"content="text/html;charset=UTF-<form名稱:<inputtype="text<inputtype="submitvalue="提交<a GETGETrequest.getParameter()獲取的數(shù)據(jù)是被服務(wù)ISO-8859-1UTF-
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年便利店加盟店能耗監(jiān)控與管理合同3篇
- 2024年裝修項目勞務(wù)分包合作合同版B版
- 二零二五年度住宅小區(qū)消防設(shè)施應(yīng)急演練與維保協(xié)議3篇
- 二零二五年度單間租賃合同(含租客信用評估體系)3篇
- 二零二五年度光伏發(fā)電項目分包合同交底與運維方案3篇
- 2024版多個人股權(quán)轉(zhuǎn)讓協(xié)議書
- 2024年白酒代工生產(chǎn)及品牌授權(quán)協(xié)議版
- 二零二五年度亮化燈具綠色認證采購合同3篇
- 2025版鈾礦開采權(quán)轉(zhuǎn)讓與放射性污染防治合同3篇
- 漂浮導(dǎo)管護理
- 民航空乘英語全套教學(xué)課件
- 2024奧數(shù)競賽5年級培訓(xùn)題-答案版
- 主題班會記錄表20篇
- 2024年北京通建信息系統(tǒng)有限公司招聘筆試參考題庫含答案解析
- 秦代建筑配色特征研究報告
- 安徽省建設(shè)工程工程量清單計價依據(jù)說明
- 冷庫安全操作規(guī)程培訓(xùn)
- 省級非急救醫(yī)療轉(zhuǎn)運管理規(guī)范
- 課程設(shè)計DLP4-13型鍋爐中硫煙煤煙氣袋式除塵濕式脫硫系統(tǒng)設(shè)計
- 煤泥綜合利用的可行性研究報告
- 三年級《剪窗花》課件
評論
0/150
提交評論