0% found this document useful (0 votes)
14 views6 pages

Javax - Servlet.http Package Methods

MSBTE Computer science and Engineering student Study material

Uploaded by

harshdpatil677
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

Javax - Servlet.http Package Methods

MSBTE Computer science and Engineering student Study material

Uploaded by

harshdpatil677
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
WB Aavances Java Prog 7.1 Intertace HttpServielRequeat The interface Hitervatieaustwnates an HIT Serv wb nfrmaton abut x request. This ie ‘ ‘The Table 6.73 hy That ntertace tena the Servet hguent trace tw pray requet formation fof SSE Sommonty uted methods ef this interface ‘Table 6.7.3 : Methods of HitpServietRaquest Interiace String getAuthTypet ) Returns the hamé fetus the portion of the request URI that indica request. Cookie! | petcookies( ) Retums an array contalniog this request. String getCantextPath| ) Jong getDateHeader(String name} Returns the value of the specified represents a Gate abject. | String petHeader(String mame} Racuras the value of the specified request header 2s 2 SUN, ea ene Terur an eaumersion cf ll ebeaider names this request contains; getHieadesNames( ) Int getintHender{String name} ‘Returns the value ofthe snecilied request header es an int. Sriag geese.) Returns the name of the HTTP method with which this request Was for example, GET, OST, or PUT, ‘String getPathinfol ) fieturns any extra path information associated with the URL the client. whee It made this request. ‘String getPethTranslated{ ) Returns any extra path information after the servlet name but ‘query string. and translates itto areal path. String getQueryString } Returns the query string that is contained in the request URL after the pi ‘String getRemoteLser| ) Returns the togin of the user making this request, |f the user ‘has be ‘authenticated, or ull the weer has not been authenticated. String gotRequestedsessiontdl } | Returns the session 1D specified by the client string getiequestuni(} fetuins dha part ofthis request’s URL from the protocol name up tai query string inthe fst ine ofthe HTTF fequast String ButfedgetRequestURy } ‘Reconstructs the UML the client used to make the request String getServietPath( ) Returns the part ofthis request's URL that calls the servlet. HripSession getSession| } Returns the current session associated with this request, or if the: ‘does not have a session, crestes one. i fugieason | Returns the current HetpSession associated with this request or, if t {getSessian{booleancreate) ho current session and create is ue, returns a new sessien, URL. 6.7.2 Interface HttpServietResponse The interface HttpServietResponse en: defined as ES eel ae Che jecks whether the requested session ID carne In vs a caokie SS ee Cheech ‘GccumeR ian nt Sre | Checks whether the requested session 1D ls stil valid Validate the provided username and password in the password validation Fealm used by the web contsiner login mechanism configured for the SerletContext, Establish mull as the value returned wher: getUserPrincipal, getRemoteUser, _ and getAuthTyne [s called on the request. 3 Whether the requested sessian ID came in-as part of the request lables a Servlet to formulate an HTTP response ta a client, This interface is public tnterlace HupSeniRtespose vacade Servis 9 fa This re ce ae the ServietResponse interface to provide HTTP-specific functionality in sending 8 response. For example, Methods to access HTTP headers and cookies. The Table 6.7.4 contains the commonly used methads of this interface. Method vold addCookie(Cookie cookie) | void addDatcHeaderistring name, lang date} | vold addtteader(string name, string value} Table 6.7.4; Methods of HitpServietResponse Interface Description ‘Adds the specified cookie to the response. Adds a response header with the given name and date-value. Adds a response header with the given name and value. | Wold addintHeader(string name, intvalue) a ere name) ‘Adds # response header with the given name and integer value. Retums a boolean indicating whether the named response header has already been set | String encodeRedirectURL(String url) Die Encodes the specified URL for use in the sendRedirect{ ) method or, ifencoding is not needed, returns the URL unchanged Encodes the specified URL by Including the session ID in it, or, encoding /s not needed, returns the URL unchanged. Sends an error response to the client using the specified status code and clearing the buffer. ‘sends an error resportse to the cllent using the specified status, Sends a temporary redirect response to the dient using the specified redirect location URL. Sets a respanse header with the given name and date-value + | Deserta name an value erunh nese [ie ‘ ead ope patiendertira name, tring lun], _| Sets resvenees arya response header WA! ssporise. _ seuthe en coe REE — 1 nae ythegiven name vold setintiteadertString name, int walle) void setStarusfint sc) 6.7.3 Intertace HtipSesston aL fusxGciated With an ier stare Information th an writ ‘The interface HttpSossion enables a Servlet to read session, This Interfaer ie defined as Se = — J ile Tater pisit to a Web site and to ston, we than ane page Feuer tied in the Table 67.5 The sestion provides 4 way to identity w user across mor Information about (hat user. Several of les methods are summarl sion taterace a _ Table 6.7.5 : Methads of HttpSeasion TT __ 1 Description = —- ‘Method - | SE —| Se in ees gre RETO: specified name In this session, oy object pethtertsutststeiig rane) 9 the abject bol (Object getAttribute(string name) Returns tie ob ane uit ifne object & bound under t a | Erumeronesrigs graben) | ining the ames ot eG RGR) REE oa the objects bound to thissession SS 7 ghar this session war created, measured in Geert cenit) © | Returns the tme wie miiseoonds dace midnight January 3, 1870. GMT: ey ler assigned to thy aeturne w string containing the unique identifi Stein wets) session r | Jong getLastaccessedTime| ) Returns the last time the client sent a request eeouaee ‘With this Teasian, asthe number of milliseconds since midnight January 1, 2970 GM, andmiarkod by the time the container received the request, int getMaxinactivalntervalf ) Reluiny the maximum dime interval, in seconde, that the servlet container wll keep this session opan betwaen client accesses. old Invalidate{ } Jnvalidates this session then unbinds any objects bound to It boolean isNew! } Returns true if the client does not yet know about the session or it| the cli¢nt chooses not tp join the session. Sold ramawoAtelbutel String name) Removes specified attribute wold setArtrbute(String name, Object value) | Binds an objec to this session, using the name specified vold setMaxinactivetmervalfint Interval) Specifies the time, In seconds, between client requests before the Servlet container will invalidate this session, Allefthese methods throw an|licgaiStateException if the session has already beeninvalidated 6.7.4 Interface HttpSessionBindingListenar The HetpSessioniindiogtlstener interface ls implementa: : implemented by objects th in ‘Gr unbound from an HTTP session. The signature of this interface i: anes ee iid when Wey are bound te public titerface HitpSesslonbl itdinig listener exicnds Even|Litener Sorviats. wring (MSBTE) This interface extends Event! istener interface, which comes under javo, util package. This interface causes an object to be notified when It's Bound to oF unbound from a session, The object is natfied by an HetpSessionBindingévent abject. ‘This may be asa result of a Serviet programmer explicitly unbinding an attribute from a session, due to a session being inated or dus to session timing out. This interface has only two methods thot are invoked when an abject ls bound or unbound. Interface Description woid valueBound(HttpSessionBindingevent event) Notifies the object that It is being bound to a session and. Identifies the session vold valuelnbound(HttpSessionBindingEvent event) | Notifies the object that it fs being unbound from a session and identifies the session. 6.7.5 Class Cookie Instance of this elass creates a cookie, a small amount of information sent by 2 Servlet to.a Web browser, saved by the ‘browser, and later sent back to the server. cookie's value can uniquely identify 2 client, so cookies are commonly used for ‘session management. This class is defined as: public class Cookie extends Object implements Cloneable & cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, 3 maximum age, and version number. Some Web brawsers have bugs in how they handle the optional attributes, so use them sparingly to improve the interoperability of yaur Servlets. The Table 6.7.6 describes the commonly used methods of Cookie class. Table 6.7.5 : Methods of Cookie Class Method Description Object clone) Overrides the standard javalang.Object.clone method to return a copy of this cookie. String getComment( ) Returns the comment describing the purpose of this cookie, or null if the cookle has no comment. —— String getDomain() Returns the domain name set for this cookie. Int getMaxAge| ) Returns the maximum age of the cookie, specified in seconds, By default, -1 indicating the cookie wil persist until browser shutdown, String gettvamet) Returns the name of the cookie. String getPath( ) Returns the path on the server to which the browser returns this cookie. Boolean gstsecurs() Returns true if the browser is sending cookies only aver a secure protocol, or a false if the browser can send cookles using any protocal. String gerValue( ) Returns the value of the cookie. nigvanionl) Returns the version of the protocol this cookie complies with. old setComment{String purpose) | Specifies a comment that describes a cookie's purpose. Void setDomain(String pattern) ‘Specifies the domain within which this cookie shauld be presented. Feel aeeaapatint expiry) ‘Sets the maximum age of the cookle in seconds. Wold satPathisering url) Specifies a path for the cookle to which the client should return the cookle. vw! A subelats of itaServer must oyerde at leat (8 doGen{ } if the wervict supports HITP GET request: (RY daPost{ J: For ITP POST requests FA) GoPut( }: For HTTP PUT requests fie] doDeletel |: For HTTP DELETE requests ‘The class Hrtgserviet i cormensinly uted when deevelonine moses HTTP regiests Tha ca, sorviety mat cece an {¥ Init Vand devtroyt)sTo manage resources that ave held For he feof te Fee tel) petServtetiniot ) (Which the sorvet uses to provide information about iteelt There's almoit no reason to avertide the servicel ) \‘Gapatching them to the handler methods for each HTTP request Type SeOptions| | and gotrace( | mecnods. The Tale 6.7.7 shows the méthode included | Table 6.7.7 {Methods of HripServiet Clase Protected vold doPut(HtipServletRequest requedt, HitpServietResponse response) throws ServietException, 1OCsception handles standard HTTP reniests by day there 6 po reason (0) OFctide te evthis Cass. Called by the server ta allow # Servet to handle a OFLETE request. ‘Called bythe serverte allow a Serviet to hacdle a GET request. ' | ee Receives an HTTP HEAD request fram tha protected service method and handles the request, Called by tna server ta allaw a Servlet to handle » OPTIONS Frequent. Calied by the terver to allow a Servet to handle 3 70ST request, Called by the server te allow a Sendet to handle 9 PUT request. ‘Description | (& Troes(HttpServietRequest Called by the server to allow 2 Servlet to handle 2 TRACE renuest 5 = |_| Protected long gettastModitied(ittpServietRequest | Returns the tne the HttpServetRequest cbyect was tact | ia modified, in milliseconds once midnight January, 1970 | J Lomr. | provected wold service(HttpServietRequest request, Recelves standard HTTP requests from the public service } ee oe rnethod and dispatches them to the da100X| | methods ’ Retention defined in this lass oe | Dispatches clon requests to ne protected service) | )CException mein | 67.7 Class HttpSessionEvent ‘The HttpSessionE-ventclass encapsulates session events it extendsEventObject and is generated when a change otcurs tothe session. The signature of this class i: [Diatiis cass itp Siontvent extends java ual Brembo } “This class provides one constructor. tt is fallowing 4. HttpSessionEvent{HrtpSession source} This constructor constructs 3 session event from the given source. This dass has only one method. tis: 2. HetpSession getsession( ) This method return the current session. 67.8 Class HitpSessionBindingEvent ‘The class HttpSessionBindingtvent extends HitpSessionEvent It is generated when a listener is bound or unbound in ‘an HutpSession object. tt is also generated when an attribute is bound or unbound. Following ar= the constructors of this dass L._ HttpSessionBindingévent(HttpSession session, String nome) 2. HttpSessionBindingEvent/HttpSession session, String name, Object vel) fete, session is the source of the event and name fs the marie associated with the object that Is being bound or ‘mbound if an attribute is being bound or unbound, its valu is passed in val, The Table 6.7.8 shows the methods included ‘Table 6.7.8 : Methods of HitpSessionBindingEvent Ciass Description Returns the name with which the attribute is bound to or unbound from the session. etumns the valve ofthe attribute that has Deen added, removed or teptaced

You might also like