Ashes Ashes - 1 year ago 77
Java Question

how to pass a collection object in response.sendRedirect

in a jsp page say x.jsp ,i have

if (some task =true)
//show xml at run time
List <User_Registration> list = dao.selectemailmobile(login); //here m getting data from Db and m getting it perfectly alright
//i wanted to pass this list parameter as List<Bean> list=List<Bean>();
//this page will show xml at run time

//some status code
//this working fine

what i tried

1.pass this(List) parameter as list i have shown,but when i'm retrieving it, is says

cannot cast from string to List<Bean>

for that i also tried to type cast it,but nothing happens.

2.setting that List in session it shows

unchecked cast from object to List<Bean>

3.using request Dispatcher

i get same cannot cast from string to List<Bean>

my code for that xml page

<%@ page language="java" contentType="text/xml; charset=ISO-8859-1"
<%@page import="com.xml.*" %>
<%@page import="com.beans.*" %>
<%@page import="java.util.*" %>

<%@page import="com.xml.ForgotPasswordXml"%>
<%!java.util.List<User_Registration> list= null; %>
HttpSession session2=request.getSession();

}catch(Exception e)

any help would be appreciated.thnks

Answer Source

You can set the list in session as


And in the next page retrieve the list as

List<Bean> list = (List<Bean>) request.getSession().getAttribute("list");


List<Bean> list = new ArrayList<Bean>();  

Note the type cast, it will avoid Type mismatch exception.

And if the list isn't needed further, remove it from the session as (optional)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download