版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
SoEasy列之RequestResponseRequestWebWebWeb應(yīng)用程序運(yùn)行機(jī)制中很重要的內(nèi)容——Request與Response。首先,我們先來(lái)看一看Request與ResponseWeb通過(guò)上圖的Web應(yīng)用程序運(yùn)行機(jī)制,我們可以知道關(guān)于Request與ResponseWeb應(yīng)用程序接收一次請(qǐng)求,就創(chuàng)建一個(gè)Request對(duì)象和Response通過(guò)Request通過(guò)ResponseRequestResponseWebTomcat(JavaEE并沒(méi)有Request與Response的實(shí)現(xiàn)類JavaEEjavax.servlet.httpHttpServletRequestHttpServletResponse接口,javax.servletServletRequestServletResponse接口。javax.servlet包中的ServletRequest和ServletResponse接口是與協(xié)議無(wú)關(guān)的,而javax.servlet.http包中的HttpServletRequest和HttpServletResponse接口是與HttpRequest這個(gè)對(duì)象不用事先,就可以在JSP網(wǎng)頁(yè)中使用,在編譯為Servlet之后,它會(huì)轉(zhuǎn)換javax.servlet.http.HttpServletRequest,HttpServletRequestIP,客戶端瀏覽器等等信息。Response對(duì)象用于動(dòng)態(tài)響應(yīng)客戶端控制發(fā)送給用戶的信息并將動(dòng)態(tài)生成響應(yīng)o對(duì)象只提供了一個(gè)數(shù)據(jù)集合,它用于在客戶端寫入值。若指定的不存在,創(chuàng)建它。若存在,則將自動(dòng)進(jìn)行更新。結(jié)果返回給客戶端瀏覽器。掌握ResponseResponseWebServletservice()方法的一個(gè)參數(shù),類型為javax.servlet.http.HttpServletResponse??蛻舳嗣看伟l(fā)送請(qǐng)求時(shí),服務(wù)器都會(huì)創(chuàng)建一個(gè)ResponseServlet接口的service()方法,來(lái)完成向客戶端的響應(yīng)工作。javax.servlet.http.HttpServletResponse常用的APIMethod name,longAddsaresponseheaderwiththegivennameanddate- name, Addsaresponseheaderwiththegivennameand Sendsatemporaryredirectresponsetotheusingthespecifiedredirectlocation name,longSetsaresponseheaderwiththegivennameanddate- name, SetsaresponseheaderwiththegivennameandsetStatus(intSetsthestatuscodeforthisjavax.servlet.ServletResponse常用的APIMethodReturnsaPrintWriterobjectthatcansendcharactertextto Setsthecharacterencoding(MIMEcharset)oftheresponsebeingsenttothe,forexample,toUTF-8. Setsthecontenttypeoftheresponsebeingsenttothe,iftheresponsehasnotbeencommittedyet.針對(duì)HttpServletResponseServletResponse常用的APIResponse一下利用HttpServletResponse來(lái)完成重定向的功能。ServletpublicpublicclassResponseServlet1extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}在Web工程的web.xml文件中Servlet<?xml<?xmlversion="1.0"encoding="UTF-<web-app " <<<創(chuàng)建一個(gè)HTML<!DOCTYPE<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01<metahttp-equiv=" <metahttp-equiv="description"content="thisismy<metahttp-equiv="content-type"content="text/html;將Web工程發(fā)布到Tomcat服務(wù)器,并啟動(dòng)Tomcat打開(kāi)瀏覽器,在地址欄中輸入在瀏覽器地址輸入U(xiǎn)RL,服務(wù)器端的Servlet,這是第一次發(fā)送的請(qǐng)求Servlet做出處理,重定向到index.html頁(yè)面,并響應(yīng)給服務(wù)器端接收到客戶端的第二次請(qǐng)求后,并響應(yīng)index.html其實(shí)Response對(duì)象提供了sendRedirect(Stringlocation)publicpublicclassResponseServlet1extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}Response對(duì)象提供了sendRedirect(Stringlocation)方法可以完成重定向的功能,實(shí)現(xiàn)登錄功能創(chuàng)建一個(gè)用于登錄的HTML<!DOCTYPE<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01<metahttp-equiv="content-type"content="text/html;<formid="form1"action="/09_request&response/response2"用戶名:<inputtype="text:<inputtype="password"<inputtype="submitvalue="登錄ServletpublicclassResponseServlet2extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ 內(nèi)Stringusername=request.getParameter("username");Stringpassword=//登錄成功PrintWriterout=response.getWriter();}}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}在Web工程的web.xml文件中Servlet<?<?xmlversion="1.0"encoding="UTF-<web-app" <<<將Web工程發(fā)布到Tomcat服務(wù)器,并啟動(dòng)Tomcat打開(kāi)瀏覽器在地址欄中輸 論一下利用HttpServletResponse來(lái)完成自動(dòng)刷新的功能。Servlet5秒鐘后自動(dòng)刷新頁(yè)面的功能(自動(dòng)跳轉(zhuǎn)到登錄頁(yè)面publicpublicclassResponseServlet3extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{PrintWriterout=response.getWriter();}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}在Web工程的web.xml文件中Servlet<?<?xmlversion="1.0"encoding="UTF-<web-app" <<<將Web工程發(fā)布到Tomcat服務(wù)器,并啟動(dòng)Tomcat打開(kāi)瀏覽器,在地址欄中輸入在學(xué)習(xí)HTML技術(shù)的時(shí)候,我們知道在head中有meta,該同樣可以完成自動(dòng)刷新頁(yè)面的功能<!DOCTYPE<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01<metahttp-equiv=" <metahttp-equiv="description"content="thisismy<metahttp-equiv="content-type"content="text/html;<metahttp-equiv="refresh"使用Response對(duì)象的setHeader()方法與HTML頁(yè)面的<meta>,同樣可以完成頁(yè)面自動(dòng)刷新功能,但是兩<!DOCTYPE<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01<metahttp-equiv=" <metahttp-equiv="description"content="thisismy<metahttp-equiv="content-type"content="text/html;<metahttp-equiv="refresh"<scriptvartimes=function ementById("times").innerHTML=times;}<body<h1>當(dāng)前頁(yè)面會(huì)在<spanid="times"></span>秒鐘后自動(dòng)跳轉(zhuǎn)到登錄頁(yè)面在學(xué)習(xí)Http響應(yīng)協(xié)議時(shí),我們知道響應(yīng)協(xié)議中有三個(gè)頭信息可以瀏覽器本地緩存,分別Cache-Control、Pragma和ExpiresServletpublicpublicclassResponseServlet4extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{PrintWriterout=response.getWriter();out.println("當(dāng)前時(shí)間是:"+newDate().toString()); }publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}在Web工程的web.xml文件中Servlet<?<?xmlversion="1.0"encoding="UTF-<web-app" <<<打開(kāi)瀏覽器,選擇“工具”->“Internet選項(xiàng)”->“瀏覽歷史記錄”中的“設(shè)置”->“查看文在瀏覽器在地址欄中輸 進(jìn)行這時(shí)再查看瀏覽器緩存內(nèi)容的文件夾,會(huì)發(fā)現(xiàn)產(chǎn)生了這次的緩存內(nèi)容這時(shí)再查看控制臺(tái)信息會(huì)發(fā)現(xiàn)打印了相關(guān)內(nèi)容說(shuō)明客戶端成功了服務(wù)器端的Servlet這時(shí)再次地址,會(huì)發(fā)現(xiàn)內(nèi)容不再由于IE瀏覽器的本地緩存問(wèn)題,第二次再次相同Servlet路徑時(shí),不會(huì)再服務(wù)器端的Servlet,而是本地緩存內(nèi)容。要想每次客戶端都到服務(wù)器端的Servlet的話,我們需要瀏覽器緩存機(jī)制。publicpublicclassResponseServlet4extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ response.setHeader("Cache-Control","no-cache");response.setHeader("Pragma","no-cache");response.setDateHeader("Expires",-1);PrintWriterout=response.getWriter(); }publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}重新發(fā)布Web工程到Tomcar服務(wù)器,并重啟Tomcat這時(shí)再次地址ResponseHttp協(xié)議的響應(yīng)協(xié)議中,除了響應(yīng)頭信息之外,還有響應(yīng)體,如何利用Response對(duì)象向客戶端發(fā)送響應(yīng)體呢?可以利用Response對(duì)象的ServletpublicpublicclassResponseServlet5extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{PrintWriterout=response.getWriter();out.println(" out.println("</BODY>");}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}在Web工程的web.xml文件中Servlet<?<?xmlversion="1.0"encoding="UTF-<web-app" <<<打開(kāi)瀏覽器,在地址欄中輸入需要注意的是,調(diào)用Response對(duì)象的setCharacterEncoding()方法設(shè)置編碼字符集時(shí),必須要在調(diào)用ResponsegetWriter()getOutputStream()方法之前。重新打開(kāi)IE瀏覽器,在地址欄中輸入但是打開(kāi)火狐瀏覽器在地址欄中輸入查看火狐瀏覽器的字符集編碼,會(huì)發(fā)現(xiàn)并不是utf-8這說(shuō)明利用Response對(duì)象的setCharacterEncoding()方法雖然可以設(shè)置響應(yīng)體內(nèi)容的編碼字符集,但并不能通過(guò)瀏覽器,瀏覽器顯示默認(rèn)使用的編碼集還是瀏覽器默認(rèn)設(shè)置的。可以調(diào)用Response對(duì)象的setContentType()方法設(shè)置響應(yīng)體的文件類型和編碼字符集。重新打開(kāi)火狐瀏覽器在地址欄中輸入Response對(duì)象的setCharacterEncoding方法設(shè)置的編碼字符集的。所以,實(shí)際上只調(diào)用利用Response對(duì)象的getWriter()方法或getOutputStream()方法向客戶端進(jìn)行響應(yīng)的時(shí)候需要注如果需要手動(dòng)響應(yīng)內(nèi)容的時(shí)候,使用getWriter()方法,否則使用getOutputStream()方法和getWriter()getOutputStream()方法只能向客戶端響應(yīng)體,而不能修改響應(yīng)行和響omcat利用Response對(duì)象向客戶端進(jìn)行響應(yīng)的功能來(lái)完成頁(yè)面中生成的案例具體實(shí)現(xiàn)步驟如創(chuàng)建一個(gè)HTML頁(yè)面用于顯示生成的<!DOCTYPE<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01<metahttp-equiv=" <metahttp-equiv="description"content="thisismy<metahttp-equiv="content-type"content="text/html;<img創(chuàng)建一個(gè)Servlet用于生成頁(yè)面實(shí)現(xiàn)的publicclassResponseServlet6extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ *Java生 1*創(chuàng) ,需要定 *newBufferedImage(寬度,高度 類型intwidth=intheight=BufferedImageimage=newBufferedImage(width,height,2繪 *通過(guò)創(chuàng)建 Graphics2Dgraphics2d=(Graphics2D)image.getGraphics();graphics2d.fillRect(0,0,width,3graphics2d.drawRect(1,1,width-1,height-1);4 內(nèi) *word表示生 graphics2d.setFont(newFont("新宋體"Font.BOLD24));Stringword= //這段代碼用于將生成 內(nèi)容寫入 中Randomrandom=newintx=for(inti=0;i<4;i++)"-30-30"之間intjiaodu=random.nextInt(60)-轉(zhuǎn)換角度為弧度doubletheta=jiaodu*Math.PI/intrandomIndex=//獲取用 charc=//將字符寫入 graphics2d.rotate(theta,x,20);graphics2d.drawString(c+"",x,20);graphics2d.rotate(-theta,x,20);設(shè)置下一個(gè)字符出現(xiàn)的水平坐標(biāo)x+=}//5繪制干擾線for(inti=0;i<10;i++){intx1=random.nextInt(width);intx2=random.nextInt(width);inty1=random.nextInt(height);inty2=graphics2d.drawLine(x1,y1,x2,}6//7將生成 ImageIO.write(image,"jpg",}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}在Web工程的web.xml文件中Servlet<?<?xmlversion="1.0"encoding="UTF-<web-app" <<<打開(kāi)瀏覽器,在地址欄中輸入如果的內(nèi)容設(shè)置為中文的話只需要將上述代碼中的word變量的值設(shè)置為常用漢字即可到目前為止,生成的需要每次刷新頁(yè)面才能重新生成,如何實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊圖片改變內(nèi)容呢?具體實(shí)現(xiàn)步驟如下:需要在顯示的HTML頁(yè)面中,使用JavaScript代碼來(lái)實(shí)現(xiàn)<!DOCTYPE<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01<metahttp-equiv=" <metahttp-equiv="description"content="thisismy<metahttp-equiv="content-type"content="text/html;<scriptfunction ementById("myimg").src=}<imgsrc="/09_request&response/response6"id="myimg"onclick="change();"style="cursor:pointer;">利用之前掌握的通過(guò)設(shè)置響應(yīng)頭信息中的內(nèi)容,瀏覽器保存緩存內(nèi)容response.setHeader(response.setHeader("Cache-Control","no-cache");response.setHeader("Pragma","no-cache");response.setDateHeader("Expires",-1);通過(guò)設(shè)置img每次請(qǐng)求的URL地址不同解決這個(gè)問(wèn)題ementById("myimg").src掌握Requesteet是ebervet接口的serve(方法的一個(gè)參x.servt.t.teveteeeetervet接口的serve()方法,來(lái)完成向客戶端的請(qǐng)求工作。javax.servlet.httpHttpServletRequest常用的APIMethodReturnstheportionoftherequestURIthatindicatesthecontextofthe Returnsthevalueofthespecifiedrequestheaderasalongvaluethatrepresentsa ReturnsthevalueofthespecifiedrequestheaderasaReturnsanenumerationofalltheheadernamesthisrequest ReturnsallthevaluesofthespecifiedrequestheaderasanEnumerationof ReturnsthevalueofthespecifiedrequestheaderasanReturnsthenameoftheHTTPmethodwithwhichthisrequestwasmade,forexample,ReturnsanyextrapathinformationassociatedwiththeURLthesentwhenitmadethisReturnsthequerystringthatiscontainedintherequestURLaftertheReturnsthepartofthisrequest'sURLfromtheprotocolnameuptothequerystringinfirstlineoftheHTTPReconstructstheURLtheusedtomaketheReturnsthepartofthisrequest'sURLthatcallsthejavax.servlet.ServletRequest常用的APIMethodReturnsthenameofthecharacterencodingusedinthebodyofthisReturnstheMIMEtypeofthebodyoftherequest,ornullifthetypeisnot ReturnsthevalueofarequestparameterasaString,ornulliftheparameternotReturnsthenameandversionoftheprotocoltherequestusesinthe ServletContext.getRealPath(java.lang.String)ReturnstheInternetProtocol(IP)addressoftheorlastthatsentReturnsthefullyqualifiednameoftheorthelastthatsenttheReturnstheInternetProtocol(IP)sourceportoftheorlastthatsent ReturnsaRequestDispatcherobjectthatactsasawrapperfortheresourcelocatedatthegivenpath.ReturnsthehostnameoftheservertowhichtherequestwasReturnstheportnumbertowhichtherequestwasHttpHttp請(qǐng)求協(xié)議包含請(qǐng)求行、請(qǐng)求頭及請(qǐng)求體三個(gè)部分。首先我們來(lái)討論請(qǐng)求協(xié)議中的請(qǐng)求行,請(qǐng)求行包含請(qǐng)求方式、請(qǐng)求及GET方式的參數(shù)和Http請(qǐng)求協(xié)議版GETGETGET/07_http/01_get.html?username=zhangsanPOSTPOSTPOST/07_http/02_post.html獲取HttpgetMethod()Http請(qǐng)求協(xié)議的請(qǐng)求方式,例如GET或POSTgetQueryString()Http請(qǐng)求協(xié)議GET方式的請(qǐng)求參數(shù)。ServletpublicpublicclassRequestServlet1extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{獲取請(qǐng)求方式,GET或獲取請(qǐng)求路徑URI和}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}在Web工程的web.xml文件中Servlet<?<?xmlversion="1.0"encoding="UTF-<web-app" <<<將Web工程發(fā)布到Tomcat服務(wù)器,并啟動(dòng)Tomcat打開(kāi)瀏覽器,在地址欄中輸 在地址后增加參數(shù)端IP地址和getContextPath()方法獲取Web工程虛擬 //獲取Web工程虛 名 服務(wù)器端Servlet路徑)獲取服務(wù)器端Stringpath 下面我們來(lái)討論Http請(qǐng)求協(xié)議中的請(qǐng)求頭信息,下面是一個(gè)HttpAccept:Accept:application/x-ms-application,image/jpeg,application/xaml+xml,image/gif,image/pjpeg,application/x-ms-xbap,*/*User-Agent:Mozilla/4.0(compatible;MSIE8.0;WindowsNT6.1;WOW64;Trident/4.0;qdesk2.5.1277.202;SLCC2;.NETCLR2.0.50727;.NETCLR3.5.30729;.NETCLR3.0.30729;MediaCenterPC6.0;.NET4.0C;.NET4.0E;Accept-Encoding:gzip,If-Modified-Since:Thu,11Sep201402:44:35GMTIf-None-Match:W/"679-1410403475587"Host:localhost:8080Connection:Keep-Alive我們之前曾利用請(qǐng)求頭信息中的Referer首先我們創(chuàng)建一個(gè)的主頁(yè)面<!DOCTYPE<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01<metahttp-equiv=" <metahttp-equiv="description"content="thisismy<metahttp-equiv="content-type"content="text/html;<ahref="refererServlet">特價(jià)商品ServletpublicclassRefererServletextendsHttpServlet處理GETpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{判斷請(qǐng)求中referer是否存在,有效Stringreferer=if(referer!=null //有效//無(wú)效 }}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}打開(kāi)瀏覽器,輸入地址在主頁(yè)面中,點(diǎn)擊“特價(jià)商品”,會(huì)返回正確內(nèi)容如果在瀏覽器地址欄中直接輸入由于直接輸入地址的請(qǐng)求協(xié)議中,沒(méi)有referer信息,所以會(huì)顯示報(bào)錯(cuò)信息RefererUser-Agent獲取客戶端瀏覽器相關(guān)Servlet用于打印User-AgentpublicpublicclassRequestServlet2extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}}在Web工程的web.xml文件中Servlet<?<?xmlversion="1.0"encoding="UTF-<web-app" <<<將Web工程發(fā)布到Tomcat服務(wù)器,并啟動(dòng)Tomcat打開(kāi)瀏覽器,在地址欄中輸入我們還可以利用getHeaderNames()Enumeration<String>Enumeration<String>names=while(names.hasMoreElements())Stringname=(String) }HttpGETPOST,GET方式的請(qǐng)求參數(shù)在請(qǐng)求行中的資源路徑后面,POST方式的請(qǐng)求參數(shù)在請(qǐng)求體中。ServletgetParameterMap()方法獲取參數(shù)以name=value形式在Map集合中將Map集合返回。首先,我們來(lái)討論P(yáng)OST方式的請(qǐng)求參數(shù),在服務(wù)器端如何獲取:創(chuàng)建一個(gè)HTML頁(yè)面編寫form<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01<metahttp-equiv=" <metahttp-equiv="description"content="thisismy<metahttp-equiv="content-type"content="text/html;<formmethod="post"<inputtype="textname="username<inputtype="password"name="password"<inputtype="radioname="gendervalue="男<inputtype="radio"name="gender"value="女"/>女<br/><inputtype="checkboxname="hobbyvalue="體育<inputtype="checkboxname="hobbyvalue="音樂(lè)<inputtype="checkboxname="hobbyvalue="讀書讀書城市<select<option <option <<optionvalue="廣州">廣州</select><textarearows="5cols="60"<inputtype="submitvalue="提交ServletpublicclassRequestServlet3extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{Stringusername=request.getParameter("username");Stringpassword=request.getParameter("password");Stringgender=request.getParameter("gender");Stringhobby=request.getParameter("hobby");Stringcity=request.getParameter("city");Stringintroduce= :"+username); :"+password); :"+gender); :"+hobby);System.out.println("城市:"+city);System.out.println("個(gè)人介紹:introduce);}}在Web工程的web.xml文件中Servlet<?<?xmlversion="1.0"encoding="UTF-<web-app" ><<<將Web工程發(fā)布到Tomcat服務(wù)器,并啟動(dòng)Tomcat打開(kāi)瀏覽器,在地址欄中輸入POST.htl在HTML在控制臺(tái)打印信息時(shí),發(fā)現(xiàn)都是亂碼。POST獲取頁(yè)面請(qǐng)求的數(shù)據(jù)信息中“”內(nèi)容為多選框,但實(shí)際上只打印其中一項(xiàng)。需要調(diào)用String[]String[]hobby=request.getParameterValues("hobby"); :"+下面,我們來(lái)討論一下GET將HTML頁(yè)面中表單的Method改為“GETServletpublicclassRequestServlet3extendsHttpServletpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{Stringusername=request.getParameter("username");Stringpassword=request.getParameter("password");Stringgender=request.getParameter("gender");Stringhobby=request.getParameter("hobby");Stringcity=request.getParameter("city");Stringintroduce= :"+username); :"+password); :"+gender); :"+hobby);System.out.println("城市:"+city);System.out.println("個(gè)人介紹:introduce);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{}}打開(kāi)瀏覽器,在地址欄中輸入POST.htmlPOST 的 中的server.xml文件<Connector<Connectorport="8080"protocol="HTTP/1.1"RUIEncoding="utf-8"/>通過(guò)代碼進(jìn)行逆向(以用戶名為例usernameusername=URLEncoder.encode(username,"ISO-8859-1");username=URLDecoder.decode(username,"utf-8");或者也可以利用下面這種方式來(lái)解決逆向gendergender=newString(gender.getBytes("ISO-8859-1"
溫馨提示
- 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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026山東泰安市屬事業(yè)單位初級(jí)綜合類崗位招聘?jìng)淇碱}庫(kù)及1套完整答案詳解
- 2026年1月重慶市萬(wàn)州區(qū)高筍塘街道辦事處公益性崗位招聘1人備考題庫(kù)及完整答案詳解1套
- 2026云南中醫(yī)藥大學(xué)招聘第一批科研助理崗位人員(事業(yè)編制外)1人備考題庫(kù)附答案詳解
- 2026四川成都市錦江區(qū)國(guó)有企業(yè)招聘18人備考題庫(kù)參考答案詳解
- 2025河南漯河市城鄉(xiāng)一體化示范區(qū)事業(yè)單位人才引進(jìn)7人備考題庫(kù)及答案詳解(易錯(cuò)題)
- 2026太平洋財(cái)險(xiǎn)安慶中支招聘信息13人備考題庫(kù)(安徽)及答案詳解(易錯(cuò)題)
- 2026山東煙臺(tái)市萊山區(qū)事業(yè)單位招聘?jìng)淇碱}庫(kù)及完整答案詳解一套
- 2026中石油新疆銷售有限公司博州分公司招聘4人備考題庫(kù)及1套參考答案詳解
- 2026北京市某政府單位熱線值守招聘需求備考題庫(kù)附答案詳解
- 2026天津市中心婦產(chǎn)科醫(yī)院第一批人事代理制、派遣制招錄9人備考題庫(kù)完整參考答案詳解
- 【地理】期末重點(diǎn)復(fù)習(xí)課件-2025-2026學(xué)年八年級(jí)地理上學(xué)期(人教版2024)
- 2026年鄉(xiāng)村治理體系現(xiàn)代化試題含答案
- 通風(fēng)設(shè)備采購(gòu)與安裝合同范本
- 化工設(shè)備清洗安全課件
- 光伏收購(gòu)合同范本
- T∕ZZB 1815-2020 塑料 汽車配件用再生聚碳酸酯(PC)專用料
- 2025~2026學(xué)年吉林省吉林市一中高一10月月考語(yǔ)文試卷
- 天津市南開(kāi)中學(xué)2025-2026學(xué)年高一上數(shù)學(xué)期末調(diào)研模擬試題含解析
- 麻辣燙創(chuàng)業(yè)商業(yè)計(jì)劃書范文
- 微專題:突破語(yǔ)病題+2026屆高考語(yǔ)文二輪復(fù)習(xí)
- 東呈集團(tuán)內(nèi)部控制中存在的問(wèn)題及對(duì)策研究
評(píng)論
0/150
提交評(píng)論