Passing Objects
Hi all
I am trying to pass an object from a tag to a servlet. i did the following,
1. In the tag class, i put:
pageContext.getRequest().setAttribute("QList", list);
The above Tag will go to a servlet, i need to read the above request attribute in the servlet, how can i do this?, i tried List<Integer> list = (List<Integer>)request.getAttribute("QList");
, but when i tried to access the read list, it gave me NullPointerException,
any help please
Jotnarta
[562 byte] By [
jotnartaa] at [2007-11-27 11:24:05]

# 1
Hi
use session scope
1)
session.setAttribute ("qlist",list);
2)
ArrayList al = (ArrayList) session.getAttribute("qlist");
--
--
al = null;
session.setAttribute ( "qlist", null );
# 2
This might help:
As I understand it, on your JSP page any scriptlet such as this:
<%pageContext.getRequest().setAttribute("QList", list);%>
is called and executed when the JSP page is initially built and not afterwards. You cant programmatically add to the QList collection afterward via, say an 'onClick' event calling a javascript function. Perhaps that's why you're getting a null.
# 3
Thank you, Actually, I do store the list in the doStartTag() like the following:
public void doStartTag() {
pageContext.getRequest().setAttribute("QList", list);
......
renderForm();
}
public void renderForm() {
.....
<form method="post" action="http://localhost:8080/servlet>
.......
</form>
}
In the servlet class, i retrieve the stored object like this:
list = (List<Integer>)request.getAttribute("QList");
out.println( "List Size: " + list.size()); // Here, a NullPointerException generated.
I think that the list didn't stored correctly in the request Object, and so, the servlets generates a NullPointerException, am I true?>