Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

GetHTTPHeader

                         

In this section, you will learn how to get content-length, content- type, and last-modify date of a file. Here we provide a complete example that uses getHeaderFieldKey() method. Firstly create a class GetHTTPHeader and initialize a class URLConnection. Then we call openConnection() method. After that we use the try and catch block to know whether the code is working correctly or not. 

This is the method returns the key for the
nth header field. The HTTP server returns the status line. In this case, getHeaderField() method returns the status line, but getHeaderFieldKey() method returns null.


Here is the code:

import java.net.*;
import java.io.*;

public class GetHTTPHeader{
  public static void main (String[] args) throws IOException {
    try {
      URL url = new URL
(
"file:///C:/Documents%20and%20Settings/comp23/Desktop/AnimationLine.html");
      System.out.println(url);
      URLConnection con = url.openConnection();
      for (int i=0; i< 10; i++) {
        String name = con.getHeaderFieldKey(i);
        String value = con.getHeaderField(i);
        if (name == null && value == null){
          break;         
        }
        else{
          System.out.println(name + "=" + value);
        }
      }
    }
    catch (Exception e) {}
  }
}


Here is the code of this program:

C:\rose>java GetHTTPHeader
file:/C:/Documents%20and%20Settings/comp23/Desktop/AnimationLine.html
content-length=110
last-modified=Fri, 15 Jun 2007 12:02:17 GMT

C:\rose>

 

Output of this program

 

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
ejb2.0
scrolling text
Disadvantagesofanexcep
using finally exceptio
threads methods
Eclipse 3.4 session be
to set combox
javascript+save date
result tag in struts 2
point to the start of
Eclipse 3.4 session be
requestDispatcherexamp
update
List in J2ME
jspregistrationform
jpanel
Java example program t
where class files are
TextArea Frame in Java
AppletInJsp
scrolling system tray
sybase create command
how to upload image ur
insert content to text
Photoshop Effects Blue
insert data to text fi
pass param from onr js
ajax auto complete
tiles 2 spring
Eclipse 3.4 EJB
д??????д?????д????Ð
Convert Integer to Flo
Photoshop Text Effects
source code for chat p
distributed cache upda
checkbox in jsp
block list software co
resultset classes
updatetable
Building a Simple EJB
joining
Copy one or more files
btreeimplementation
FreeMarker FreeMarker
how to insert date val
begining to rdbms
Photoshop Textures and
login creation using j
OutStream
Photoshop Photo Effect
select a row of data t
list is sorted or not
javaexampleprogramuseo
GNATbench
Thread Sleep Method
swings ioc
show current directory
MemoryImageSource(widt
standard
<s:push> in struts2
how to edit a any file
AOP Example Spring
HelloWorld.shtml
swing Jlabel
JNDI tutorial'
java file browser
url redirecting in ser
Servlet Context
sample program toTake
strtuts2
Java property file
byte files
json lib/componen...]=
comparator
Transaction?
Photoshop Photo Effect
google
code for frames using
visible
С?в??в??С?в???С?
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.