wood burning stoves*
The moose likes Servlets and the fly likes HttpServletRequest.getHeaders(aString) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServletRequest.getHeaders(aString)" Watch "HttpServletRequest.getHeaders(aString)" New topic
Author

HttpServletRequest.getHeaders(aString)

Nasser Aboobaker
Ranch Hand

Joined: Dec 06, 2000
Posts: 104
Hi friends
I am getting compile time error while compiling this following code.
It says
1."No method found matching getHeaders(String)
2."Cannot parse initializer Enumeration values = req.getHeaders(name)
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HeaderSnoop extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
out.println("Request Headers");
out.println();
Enumeration names = req.getHeaderNames();
while(names.hasMoreElements()){
String name = (String)names.nextElement();
Enumeration values = req.getHeaders(name);
if(values != null){
while (values.hasMoreElements()){
String value = (String)values.nextElement();
out.println(name + ": " + value);
}
}
}
}
}

Can some one enlighten me in this matter!.
Thanks in advance
Nasser
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Nasser Aboobaker:
Hi friends
I am getting compile time error while compiling this following code.
It says
1."No method found matching getHeaders(String)
2."Cannot parse initializer Enumeration valuesCan some one enlighten me in this matter!

Maybe you have a v2.1 servlet container? I think this method was only introduced in v2.2 of the API.
- Peter

Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You are correct peter, this method was introduced with version 2.2. Version 2.1 has a getHeader method.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Nasser Aboobaker
Ranch Hand

Joined: Dec 06, 2000
Posts: 104
Hi Peter, Bosun,
thanks for your reply.
Can you advice me where to get latest servlet container and how to change the current one I am having. I have Tomcat 3.2 installed and working. Is that an old version?.
Thanks for your time and help.
Nasser
 
 
subject: HttpServletRequest.getHeaders(aString)