M
Madhur Ahuja
Hello
While studying servlets, I noticed the function,
HttpServletRequest.getHeaderNames() which successfully retreived
all the headers passed by my browser.
However I noticed that, when I run my servlet behind a local proxy,
the servlet was unable to return any headers, i.e. it returned
null although the web page was corretly displayed.
How is this possible, since every page requested from the server has
a header and browser like I.E. expect to receive some minimum headers.
Here is the program:
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.util.*;
file://see getheader.html for extension
public class GetHeader extends HttpServlet
{
public void doGet(HttpServletRequest hrq,HttpServletResponse hrp)
throws ServletException,IOException
{
InputStream is=hrq.getInputStream();
PrintWriter pw=hrp.getWriter();
hrp.setContentType("text/html");
getit(hrq,hrp,pw);
pw.println("</body>");
pw.close();
is.close();
}
public void doPost(HttpServletRequest hrq,HttpServletResponse hrp)
throws ServletException,IOException
{
doGet(hrq,hrp);
}
void getit(HttpServletRequest hrq,HttpServletResponse hrp,PrintWriter pw)
{
Enumeration headers=hrq.getHeaderNames();
while(headers.hasMoreElements())
{
String head=(String)headers.nextElement();
pw.println(head+hrq.getHeader(head));
pw.println("<br>");
}
}
}
While studying servlets, I noticed the function,
HttpServletRequest.getHeaderNames() which successfully retreived
all the headers passed by my browser.
However I noticed that, when I run my servlet behind a local proxy,
the servlet was unable to return any headers, i.e. it returned
null although the web page was corretly displayed.
How is this possible, since every page requested from the server has
a header and browser like I.E. expect to receive some minimum headers.
Here is the program:
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.util.*;
file://see getheader.html for extension
public class GetHeader extends HttpServlet
{
public void doGet(HttpServletRequest hrq,HttpServletResponse hrp)
throws ServletException,IOException
{
InputStream is=hrq.getInputStream();
PrintWriter pw=hrp.getWriter();
hrp.setContentType("text/html");
getit(hrq,hrp,pw);
pw.println("</body>");
pw.close();
is.close();
}
public void doPost(HttpServletRequest hrq,HttpServletResponse hrp)
throws ServletException,IOException
{
doGet(hrq,hrp);
}
void getit(HttpServletRequest hrq,HttpServletResponse hrp,PrintWriter pw)
{
Enumeration headers=hrq.getHeaderNames();
while(headers.hasMoreElements())
{
String head=(String)headers.nextElement();
pw.println(head+hrq.getHeader(head));
pw.println("<br>");
}
}
}