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

    sookie

    Member

    Updated: Oct 23, 2024
    Views: 1.1K
    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
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Deepika Bansal

    MemberFeb 25, 2011

    Hey sookie. What problem are you exactly facing.?
    Are you sure? This action cannot be undone.
    Cancel
  • sookie

    MemberFeb 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
    Are you sure? This action cannot be undone.
    Cancel
  • Deepika Bansal

    MemberMar 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.😀
    Are you sure? This action cannot be undone.
    Cancel
  • PraveenKumar Purushothaman

    MemberMar 2, 2011

    You can also use:
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("your url");
    request.addParameter("parameter", "value");
    dispatcher.include(request, response);
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register