• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServletRequest.getHeaders(aString)

 
Nasser Aboobaker
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct peter, this method was introduced with version 2.2. Version 2.1 has a getHeader method.

Bosun
 
Nasser Aboobaker
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic