How to pass any value as a HttpHeader from one JSP to another

sookie

sookie

@sookie-T06sFW Oct 23, 2024
Hi All,

I am facing one problem regarding passing my one value as HttpHeader[Note: not as a hidden field or parameter] from one JSP page to another. Can anyone has any idea , how can I do so using JS or JSP or anything.

Thanks!
Sookie

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Deepika Bansal

    Deepika Bansal

    @deepika-jf1ysv Feb 25, 2011

    Hey sookie. What problem are you exactly facing.?
  • sookie

    sookie

    @sookie-T06sFW Feb 26, 2011

    Deepika Bansal
    Hey sookie. What problem are you exactly facing.?
    Hey problem that I am facing is the value that I am adding to header is getting lost in my next page. I need to read that value but i couldn't find it. I have a First.jsp page in which I am adding response like following
    <%=
        response.addHeader("hello", "Hello");
    %>
    
    Now I want to go to my Second.jsp and want to get that value in Second.jsp page header. If I do redirect, this value gets lost. Any idea where I am going wrong in my approach ?

    Thanks,
    Sookie
  • Deepika Bansal

    Deepika Bansal

    @deepika-jf1ysv Mar 1, 2011

    Sookie you can use the concept of parameters. In one of my projects I used that and it worked fine for me. You can try it.

    In first page you use the following code:
    <jsp:forward page="second_page.jsp">
          <jsp:param name="msg" value="Hello."/>
    </jsp:forward>
    
    Here value of the parameter msg will be set as Hello.

    And in the second page, use the following in between the head tags:
    <head>
    String msg=request.getParameter("msg");
    </head>
    
    You'll get your message in the msg variable.


    Another way is that you can attach the values in the html header using '&' sign similar to what as we send values using the 'get' method while submitting the form.

    In your above query, you've mentioned that you don't want to use the concept of parameters. Any particular reason for that because I find it a very convenient way.😀
  • PraveenKumar Purushothaman

    PraveenKumar Purushothaman

    @praveenkumar-66Ze92 Mar 2, 2011

    You can also use:
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("your url");
    request.addParameter("parameter", "value");
    dispatcher.include(request, response);