java - How to pass an ArrayList from one jsp to another using session -
i'm trying pass arraylist handle.jsp main.jsp, doesn't let me it. keeps saying "type mismatch: cannot convert object arraylist".
main.jsp:
<%@ page import="java.util.arraylist" %> <html> <body> <h1>hobby manager</h1> <% arraylist<string> hobbies = session.getattribute("hobbies"); out.println(hobbies.size()); out.println(session.getattribute("hobbies")); %> <h2>add new hobby!</h2> <form action="handleaddhobby.jsp" method="get"> new hobby wishing add? <input type=text name=hobbyname /> <br/> <input type=submit name=addhobby value="add hobby" /> </form> </body> </html>
handle.jsp:
<%@ page import="java.util.arraylist" %> <html> <body> <% arraylist<string> hobbies = new arraylist<string>(); string hobbyname = request.getparameter("hobbyname"); if(hobbyname == null){ out.println("please enter hobby before clicking add! dummy.<br/>"); } else{ hobbies.add(hobbyname); for(int index = 0; index < hobbies.size(); index ++){ out.println(hobbies.get(index) + "<br/>"); } session.setattribute("hobbies", hobbies); } %> </body> </html>
i have tried passing string object, , passing object alone nothing seems work.
the problem here ..
arraylist<string> hobbies = session.getattribute("hobbies");
try typecasting getattribute returns object.
arraylist<string> hobbies = (arraylist<string>)session.getattribute("hobbies");
Comments
Post a Comment