hai friends
hai friends I am begginer to java, i want know how to read a html header....
plz any one give me a possible solution....:rolleyes:
thanks for helping....

Dani AI

Generated

Quick clarification before examples: “HTML header” can mean two different things. For it might mean the HTML <head> section (title, meta tags) or the HTTP headers sent with a request/response. As noted, the phrase is ambiguous; and was right to recommend learning the basics first. Below are short, practical Java snippets for the two common cases and a few troubleshooting tips.

If you need HTTP request headers on the server (Servlet):

Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
    String name = headerNames.nextElement();
    String value = request.getHeader(name); // first value if multiple
    System.out.println(name + ": " + value);
}

Notes: header names are case-insensitive. Use request.getHeaders(name) to iterate multiple values. Some headers may be added or removed by proxies or your servlet container.

If you need response headers from a remote site (Java 11+ HttpClient) or want a quick client-side check:

HttpClient client = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create("https://example.com")).GET().build();
HttpResponse<String> res = client.send(req, BodyHandlers.ofString());
res.headers().map().forEach((k,v)-> System.out.println(k + ": " + v));

If you meant HTML <head> meta tags (title, description), use an HTML parser such as jsoup:

Document doc = Jsoup.connect("https://example.com").get();
for (Element m : doc.head().select("meta[name], meta[property]")) {
    System.out.println(m.attr("name") + " -> " + m.attr("content"));
}

Troubleshooting tips: inspect raw traffic with curl or browser dev tools to confirm what’s actually sent; watch for redirects or proxies that change headers; dynamic sites may populate meta data with JavaScript (use a headless browser if needed). Start by reading the basic HTTP request/response flow and the HTML document structure — it will make the examples above much easier to follow.

Recommended Answers

All 3 Replies

It would really be better if u start from the basics rather than jumping to advanced concepts of which u have no idea. Its better to learn on your own rather than getting a code from someone and running it.

I hope u understand that just getting the solution to ur prob is not important but rather understanding the concepts behind them is more imp.

Just learn the basics and u wouldnt need any help regarding ur problem.

'hai' is Japanese for 'yes', and has no place in the sentences you used it in.
I'm not your friend.
'plz' is not a word in any language I'm aware of (and I know quite a few well enough to recognise them).
'begginer' is similarly a nonexistent word.
So is 'u' b.t.w.
html headers don't exist.

But in case you're looking for HTTP headers, they're just Strings you can get from the HTTP request as it comes in.
There are some packages which nicely parse them for you, but you can also just intercepts the raw data as it comes in to the network connection on your machine and look at it there.

Thank you very much....... for your suggestion.....I will follow that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.