File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes HTTPrequest object.  getAttribute() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTPrequest object.  getAttribute()" Watch "HTTPrequest object.  getAttribute()" New topic
Author

HTTPrequest object. getAttribute()

John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
I have long been successful communicating information from servlets to JSPs. I usually setup a dataBean object and then request.setAttribute ("dataBean",beanObject); Then in the JSP, i simply getAttribute ("dataBean") and cast the returned object to the bean's type and gain access to the dataBean's contents.
Recently, I attempted the same operation but in reverse. I setAttribute ("parmName",parmValue); in a JSP scriptlet (Java is the scripting language), and then attempted a getAttribute ("parmName") in the servlet. The resulting object is always null. I am able to do a request.getAttribute ("parmName") in the JSP and have verified that the attribute is indeed being set in the request successfully by the JSP.
Why cannot I access the attribute from the request in the servlet?
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
My guess is that the request ends shortly before the JSP is displayed, which is the response. It you click on the JSP again, that's the next (and therefore a separate) request.
Since the object has only a single request scope, you don't get it in the next request to the servlet.
(HTTP)session scope is different, of course, but then you have to take care of eliminating the object(s) from the HttpSession before it gets bloated with unneeded objects.
Let's see what others say...

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTPrequest object. getAttribute()