Import java. Io. ioexception; Import java. Io. printwriter; Import java. util. enumeration; Import javax. servlet .*; Import javax. servlet. http .*; Public class snoopservlet extends httpservlet { Public void doget (httpservletrequest request, httpservletresponse response) Throws servletexception, ioexception { Printwriter out = response. getwriter (); Response. setcontenttype ("text/plain "); Out. println ("Snoop servlet "); Out. println (); Out. println ("servlet init parameters :"); Enumeration E = getinitparameternames (); While (E. hasmoreelements ()){ String key = (string) E. nextelement (); String value = getinitparameter (key ); Out. println ("" + key + "=" + value ); } Out. println (); Out. println ("context init parameters :"); Servletcontext context = getservletcontext (); Enumeration Enum = context. getinitparameternames (); While (enum. hasmoreelements ()){ String key = (string) enum. nextelement (); Object value = context. getinitparameter (key ); Out. println ("" + key + "=" + value ); } Out. println (); Out. println ("context attributes :"); Enum = context. getattributenames (); While (enum. hasmoreelements ()){ String key = (string) enum. nextelement (); Object value = context. getattribute (key ); Out. println ("" + key + "=" + value ); } Out. println (); Out. println ("request attributes :"); E = request. getattributenames (); While (E. hasmoreelements ()){ String key = (string) E. nextelement (); Object value = request. getattribute (key ); Out. println ("" + key + "=" + value ); } Out. println (); Out. println ("servlet name:" + getservletname ()); Out. println ("Protocol:" + request. getprotocol ()); Out. println ("Scheme:" + request. getscheme ()); Out. println ("server name:" + request. getservername ()); Out. println ("server port:" + request. getserverport ()); Out. println ("server info:" + context. getserverinfo ()); Out. println ("remote ADDR:" + request. getremoteaddr ()); Out. println ("remote host:" + request. getremotehost ()); Out. println ("character encoding:" + request. getcharacterencoding ()); Out. println ("Content Length:" + request. getcontentlength ()); Out. println ("content type:" + request. getcontenttype ()); Out. println ("locale:" + request. getlocale ()); Out. println ("Default Response Buffer:" + response. getbuffersize ()); Out. println (); Out. println ("parameter names in this request :"); E = request. getparameternames (); While (E. hasmoreelements ()){ String key = (string) E. nextelement (); String [] values = request. getparametervalues (key ); Out. Print ("" + key + "= "); For (INT I = 0; I <values. length; I ++ ){ Out. Print (Values [I] + ""); } Out. println (); } Out. println (); Out. println ("headers in this request :"); E = request. getheadernames (); While (E. hasmoreelements ()){ String key = (string) E. nextelement (); String value = request. getheader (key ); Out. println ("" + key + ":" + value ); } Out. println (); Out. println ("cookies in this request :"); Cookie [] cookies = request. getcookies (); If (cookies! = NULL ){ For (INT I = 0; I <cookies. length; I ++ ){ Cookie = Cookies [I]; Out. println ("" + Cookie. getname () + "=" + Cookie. getvalue ()); } } Out. println (); out. println ("request is secure:" + request. issecure (); out. println ("auth type:" + request. getauthtype (); out. println ("HTTP Method:" + request. getmethod (); out. println ("remote user:" + request. getremoteuser (); out. println ("request URI:" + request. getrequesturi (); out. println ("context path:" + request. getcontextpath (); out. println ("Servlet Path:" + request. getservletpath (); out. println ("Path Info:" + request. getpathinfo (); out. println ("path trans:" + request. getpathtranslated (); out. println ("query string:" + request. getquerystring (); Out. println (); Httpsession session = request. getsession (); Out. println ("requested session ID:" + Request. getrequestedsessionid ()); Out. println ("current session ID:" + session. GETID ()); Out. println ("session created time:" + session. getcreationtime ()); Out. println ("session last accessed time:" + session. getlastaccessedtime ()); Out. println ("session Max inactive interval seconds:" + session. getmaxinactiveinterval ()); Out. println (); Out. println ("session values :"); Enumeration names = session. getattributenames (); While (names. hasmoreelements ()){ String name = (string) names. nextelement (); Out. println ("" + name + "=" + session. getattribute (name )); } } } |