tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anoop kumar V <anoopkum...@gmail.com>
Subject Re: request.getHeader() gives null
Date Sun, 05 Feb 2006 04:39:24 GMT
I would really appreciate if someone can answer my question..

Thanks,
Anoop

On 2/3/06, Anoop kumar V <anoopkumarv@gmail.com> wrote:
>
> HI All,
>
> I am using Tomcat5.
> I have a simple jsp displaying the header information that I have set in
> another jsp page. For some reason I can see all the default headers except
> the headers that I have set in this jsp. I am doing a jsp:forward to go to
> the next page which displays the header information ( I have also tried
> redirect - but just wont work)...
>
>
> ------------------------------------------------------------------------------------------------------------
> ------------------------------------------
> index.jsp----------------------------------------------------
>
> ------------------------------------------------------------------------------------------------------------
>
> <%@ page import="java.io.PrintWriter"%>
> <%--
>  @author <a href="mailto: akumar@iditarodsys.com">Anoop Kumar V.</a>
>          Date: Jan 19, 2006 4:13:05 PM
> --%>
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> <html>
>   <head><title>Simple jsp page to show header values</title>
>   </head>
>   <body>
>
>   <br/>
>   <%
>       System.out.println("Jsp called successfully");
>
>       response.addHeader("userName","GSE_FMS");
>       response.setHeader("userName","GSE_FMS");  //just to be sure.....
>       response.addHeader("myValue","theValue");
>
>       boolean isheader = response.containsHeader("userName");
>
>       System.out.println("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ncontains
> userName header ..."+isheader);
>       System.out.println("contains myValue header ..." +
> response.containsHeader("myValue"));
>       //response.sendRedirect("/TestHeaderResponse.jsp");
>
>   %>
>   <jsp:forward page="/TestHeaderResponse.jsp"/>
>   </body>
> </html>
>
> ------------------------------------------------------------------------------------------------------------
> --------------------------
> TestHeaderResponse.jsp----------------------------------------------
>
> ------------------------------------------------------------------------------------------------------------
> <%@ page import="java.util.Enumeration"%>
> <%--
>  Created for Sikorsky GSE
>  @author <a href="mailto: akumar@iditarodsys.com">Anoop Kumar V.</a>
>          Date: Jan 19, 2006 4:13:05 PM
> --%>
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> <html>
>   <head><title>Simple jsp page to show header values</title>
>   </head>
>   <body>
>   <br/>
>   <%
>       System.out.println("Test header response page called successfully");
>
>
>       String s = request.getHeader("userName");
>       System.out.println("user: "+s);           // Issue: always returns
> null even though set in the previous page
>       out.println("USERNAME HEADER: " + s +"<br/>");
>
>       Enumeration headernames = request.getHeaderNames();
>       System.out.println("Headers---------");
>       while (headernames.hasMoreElements()){
>           String headername = (String)headernames.nextElement();
>           String headervalue = request.getHeader(headername);
>           System.out.println(headername+"----"+headervalue);
>           out.println("    " + headername+"----"+headervalue + "<br/>");
>           out.flush();
>     }
>   %>
>   </body>
> </html>
>
> ------------------------------------------------------------------------------------------------------------
>
> I think I am doing something fundamentally wrong....
>
> Also can someone help me with understanding how the setHeader and
> getHeader works - we use response.setHeader to set but use
> request.getHeader to read the header values. Is it that the response of
> the first page becomes the request of the next jsp....
> --
> Thanks and best regards,
> Anoop
>
>


--
Thanks and best regards,
Anoop

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message