2013年12月15日星期日

About receiving the servlet session pass over the value !

servlet section
QueryGood qg = new QueryGood ();
List allgoodlist = qg.querygood (goodtype, goodname);
HttpSession session = request.getSession (true);
request.setAttribute ("allgoodlist", allgoodlist);
RequestDispatcher dispatcher = request.getRequestDispatcher ("cart.jsp");
dispatcher.forward (request, response);
jsp part cart.jsp I can receive faxes over the values.

But I would like to receive it in another querygood.jsp page <%
List list = (List) request.getAttribute ("allgoodlist");
Iterator its = list.iterator (); / / null pointer exception reporting
while (its.hasNext ()) {
Good good = new Good ();
good = (Good) its.next ();

%>
package I have also imported .
Is there any big God knows why?
------ Solution ---------------------------------------- ----
request.setAttribute("allgoodlist", allgoodlist)

you do with the request, useless session.
According scope, so cart.jsp can receive , but querygood.jsp not receive .
you should use session.setAttribute traditional values ​​, but with session. getAttribute access data on it.
------ Solution ---------------------------------------- ----
2 Floor positive solutions , request valid within the scope of the current request , the landlord has not within the scope of the current request scope , you get the value of it. In other session it
------ For reference only ----------------------------------- ----
you debug, look request.setAttribute ("allgoodlist", allgoodlist); in allgoodlist whether null
------ For reference only ------- --------------------------------

----------- -
Thanks so much , Xueyibujing ah !
------ For reference only -------------------------------------- -
+1

没有评论:

发表评论