Hi could someone help me out with a simple and (presumably quick) fix? I've recently started getting into Servlets/JSP and was wondering, I have a servlet which redirect to a JSP. I would like the JSP to display data stored in a Bean. I know how to create an instance of the bean in the servlet and set the bean attributes to the correct values (taken from another JSP), but when I redirect to the JSP page all the values ra eset to NULL. I think its something to do with the pageContext, I think the Bean data is lost during the redirect. PS: A little exmaple code would be nice, I can find nothing on the net. Thanks KPS
Hi, You could put your values in the session and then forward it to jsp. In you servlet you could set the values as : session.setAttribute("DBNAME",dbname); and get those value in your jsp as below. String name=session.getAttribute("DBNAME"); -Amol
Rather than redirecting to the JSP, you can use a RequestDispatcher to forward from the servlet to the JSP. This all takes place within the same request context so that if you place the bean on the request, it will still be there when the JSP gets executed. In contrast, a redirect causes a new request to be initiated. hth, bear
I think the Bean data is lost during the redirect.
It is not the bean data that is being lost across the redirect, but the bean itself. If you check, you will find that because a new request is initiated by the redirect that a new instance of the bean is being created for your page. hth, bear
Or you might decide to have the bean in session scope and you can use either forward or include. In this case you need to make sure you don't create another instance of the bean in the jsp page - specify the bean type and not the class. [ June 19, 2003: Message edited by: Calina Cazangiu ]
Joined: Jun 05, 2003
Well thanks for the replies but I'm still trying. However I'm getting fedup now and just want this thing to work, I've spent far too long trying to figure it out now and I fedup with it, so here goes. Thgis is my servlet and my JSP can some please just 'fill in the blanks' if you like and show me where its going wrong (probably more than one place by now), cause Im close to just giving up. detailsServlet -----------------------------------------------