1

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
response.sendredirect("page.jsp?list="+list)
//i wanted to pass this list parameter as List<Bean> list=List<Bean>();
//this page will show xml at run time

}
else 
{
//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"
pageEncoding="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; %>
<%try{
HttpSession session2=request.getSession();
System.out.println("hii");

list=(List<User_Registration>)request.getAttribute("list");
//list=(java.util.List<User_Registration>)request.getParameter("list");
System.out.println(list.toString());
}catch(Exception e)
{
e.printStackTrace();
}
%>
<%=ForgotPasswordXml.xml(list)%>

any help would be appreciated.thnks

Divya
  • 1,469
  • 1
  • 13
  • 25

2 Answers2

1

You can set the list in session as

request.getSession().setAttribute("list",list);

And in the next page retrieve the list as

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

or

List<Bean> list = new ArrayList<Bean>();  
list.addAll(session.getAttribute("list")); 

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)

request.getSession().removeAttribute("list");
Sandhu Santhakumar
  • 1,678
  • 1
  • 13
  • 24
0

Send the whole List as one JSON string and rebuild the List using the JSON . You need to use JSONObject . The other thing you can do is , set List to Session and get back the List from the session and invalidate the Session if requires .

Vivek Keshri
  • 108
  • 10