If the transition between pages is done via a link, the you're losing the
attribute, as the request is resetted as soon as page x finishes sending
it's data. When you click the link and move to page y, another request is
generated. That's why you get null when you ask for that parameter.

You would have to forward the request from page x to page y so it would pass
to page y with all the attributes set.

I think getServletContext().setAttribute() and
getServletContext().getAttribute(), works because the servlet context is
shared among the pages in the webapp (afaik)

hope this helps

Luis Javier

----- Original Message -----
From: "Aurangzeb M. Agha" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, February 10, 2003 10:37 AM
Subject: request.set|getAttribute() not working


> I'm trying to pass a value on one JSP page (x) to another JSP (y).  The
> transition from page x to page y is done via a link on page x.
>
> I was under the impression that if I wanted to pass a string from one page
> to another, I could do it using the request.
>
> Namely:
>
> <%    // on page x
> String foobar = "String to pass.";
> request.setAttribute("passedStr", foobar);
> %>
>
> <%    // on page y
> String foobar2 = (String)request.getAttribute("passedStr");
> %>
> output: <%= foobar2 %>
>
> However when I try this, the value of foobar2 on page y is _always_ null!
>
> BUT, if instead of request.setAttribute and getAttribute, I use
> getServletContext().setAttribute() and getServletContext().getAttribute(),
> things work fine!
>
> Why is this, and what's the difference?
>
> The JavaDoc for HttpServletRequest's parent class, ServletRequest says of
> setAttribute():
>
> "Stores an attribute in this request. Attributes are reset between
> requests."
>
> So what's the point of it?!  What's going on?  Is my understanding of the
> request just messed up?!
>
>         Thx in Advance,
>         Aurangzeb
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
>
> Some relevant archives, FAQs and Forums on JSPs can be found at:
>
>  http://java.sun.com/products/jsp
>  http://archives.java.sun.com/jsp-interest.html
>  http://forums.java.sun.com
>  http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

Reply via email to