This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HttpServletRequest.getHeaders(aString)  RSS feed

 
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: 1511
  • 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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!