Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
3. Example: Printing all Headers 4. Servlet and JSP Tutorial: Top 5. Servlet and JSP Training Courses On-site at your company or at public venues.
28/03/13
F r o m(email address of requester; only used by Web spiders and other custom clients, not by browsers) H o s t(host and port as listed in the original URL) I f M o d i f i e d S i n c e(only return documents newer than this, otherwise send a 304 "Not Modified"
response) P r a g m a(the n o c a c h evalue indicates that the server should return a fresh document, even if it is a proxy with a local copy) R e f e r e r(the URL of the page containing the link the user followed to get to current page) U s e r A g e n t(type of browser, useful if servlet is returning browser-specific content) U A P i x e l s ,U A C o l o r ,U A O S ,U A C P U(nonstandard headers sent by some Internet Explorer versions, indicating screen size, color depth, operating system, and cpu type used by the browser's system) For full details on HTTP headers, see the specifications at http://www.w3.org/Protocols/.
3.1 ShowRequestHeaders.java
You can also download the source or try it on-line.
p a c k a g eh a l l ; i m p o r tj a v a . i o . * ; i m p o r tj a v a x . s e r v l e t . * ; i m p o r tj a v a x . s e r v l e t . h t t p . * ; i m p o r tj a v a . u t i l . * ;
www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Request-Headers.html 2/6
28/03/13
p u b l i cc l a s sS h o w R e q u e s t H e a d e r se x t e n d sH t t p S e r v l e t{ p u b l i cv o i dd o G e t ( H t t p S e r v l e t R e q u e s tr e q u e s t , H t t p S e r v l e t R e s p o n s er e s p o n s e ) t h r o w sS e r v l e t E x c e p t i o n ,I O E x c e p t i o n{ r e s p o n s e . s e t C o n t e n t T y p e ( " t e x t / h t m l " ) ; P r i n t W r i t e ro u t=r e s p o n s e . g e t W r i t e r ( ) ; S t r i n gt i t l e=" S e r v l e tE x a m p l e :S h o w i n gR e q u e s tH e a d e r s " ; o u t . p r i n t l n ( S e r v l e t U t i l i t i e s . h e a d W i t h T i t l e ( t i t l e )+ " < B O D YB G C O L O R = \ " # F D F 5 E 6 \ " > \ n "+ " < H 1A L I G N = C E N T E R > "+t i t l e+" < / H 1 > \ n "+ " < B > R e q u e s tM e t h o d :< / B > "+ r e q u e s t . g e t M e t h o d ( )+" < B R > \ n "+ " < B > R e q u e s tU R I :< / B > "+ r e q u e s t . g e t R e q u e s t U R I ( )+" < B R > \ n "+ " < B > R e q u e s tP r o t o c o l :< / B > "+ r e q u e s t . g e t P r o t o c o l ( )+" < B R > < B R > \ n "+ " < T A B L EB O R D E R = 1A L I G N = C E N T E R > \ n "+ " < T RB G C O L O R = \ " # F F A D 0 0 \ " > \ n "+ " < T H > H e a d e rN a m e < T H > H e a d e rV a l u e " ) ; E n u m e r a t i o nh e a d e r N a m e s=r e q u e s t . g e t H e a d e r N a m e s ( ) ; w h i l e ( h e a d e r N a m e s . h a s M o r e E l e m e n t s ( ) ){ S t r i n gh e a d e r N a m e=( S t r i n g ) h e a d e r N a m e s . n e x t E l e m e n t ( ) ; o u t . p r i n t l n ( " < T R > < T D > "+h e a d e r N a m e ) ; o u t . p r i n t l n ( " < T D > "+r e q u e s t . g e t H e a d e r ( h e a d e r N a m e ) ) ; } o u t . p r i n t l n ( " < / T A B L E > \ n < / B O D Y > < / H T M L > " ) ; } p u b l i cv o i dd o P o s t ( H t t p S e r v l e t R e q u e s tr e q u e s t , H t t p S e r v l e t R e s p o n s er e s p o n s e ) t h r o w sS e r v l e t E x c e p t i o n ,I O E x c e p t i o n{ d o G e t ( r e q u e s t ,r e s p o n s e ) ; } }
www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Request-Headers.html
3/6
28/03/13
www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Request-Headers.html
4/6
28/03/13
Tutorials
Apache Tomcat Tutorial Intermediate Servlets & JSP Tutorial Advanced Servlets & JSP Tutorial Jakarta Struts Tutorial JSF 2 Tutorial Java Tutorial Ajax Tutorial jQuery Tutorial GWT Tutorial
Programming Resources
Specifications & Documentation Servers IDEs Java-Related Jobs JavaServer Faces (JSF) Books Web Hosting Providers Java Programming Resources
www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Request-Headers.html
5/6
28/03/13
Public Training Course Schedule Books Core Servlets & JSP 2nd Ed. M ore Servlets & JSP Core Web Programming Core Servlets & JSP 1st Ed. Core Servlets & JSP E-Book M ore Servlets & JSP E-Book
Consulting
Our consulting services We are hiring!
Jobs
www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Request-Headers.html
6/6