Home > Back-end >  JSP null pointer problem, a great god
JSP null pointer problem, a great god

Time:10-05

<% @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" % & gt;



<meta charset="utf-8" & gt;
Insert the title here

<body>


















<% @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" import="cc. Good" % & gt;
<% @ page import="Java. Util. *" % & gt;



<meta charset="utf-8" & gt;
Insert the title here

<body>
<% request. The setCharacterEncoding (" utf-8 ");
String goodname=request. The getParameter (" goodname ");
String price=request. The getParameter (" price ");
Good Good=new ();
Good. SetGoodname (goodname);
Good. SetPrice (price);
ArrayList & lt; Good> A=null;
The HttpSession sess=request. GetSession ();
If (session. The getAttribute (" good ")==null) {
A=new ArrayList (a);
} else {
A=(ArrayList) The session. The getAttribute (" good ");
}
A.a dd (good);
Sess. SetAttribute (" good ", a);
Response. SendRedirect (" NewFile2. JSP ");
% & gt;




<% @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" import="cc. Good" % & gt;
<% @ page import="Java. Util. *" % & gt;



<meta charset="utf-8" & gt;
Insert the title here

<body>
Name of commodity & lt;/td>
Commodity price & lt;/td>
Purchase & lt;/td>
Cell phones & lt;/td>
2000 & lt;/td>
TV & lt;/td>
5000 & lt;/td>
The washing machine & lt;/td>
3000 & lt;/td>
Air conditioning & lt;/td>
4000 & lt;/td>



<%! ArrayList 'arry;
Good Good [];
Int price; % & gt;
<%
The HttpSession ses=request. GetSession ();
'arry=(ArrayList) Ses. The getAttribute (" good ");
If (' arry!=null) {
for(int i=0; i<'arry. The size (); I++) {
Good [I]='arry. Get (I);
Price +=Integer. ParseInt (good [I]. GetPrice ());
Out.println (good [I] getGoodname ());
Out.println (good [I]. GetPrice ());
Out.println (" & lt; Br/& gt;" );
}
Out.println (" commodity price + price ");
}
% & gt;
<% %='arry & gt;



Great spirit, good [I]='arry. Get (I); Why is here to null pointer exception, how should solve

CodePudding user response:

'arry doesn't exist, not the object of sesssion,
  • Related
Name of commodity & lt;/td>
Commodity price & lt;/td>
Quantity & lt;/td>