Title: RE:
Check whether the name is null.
after
String name = selected [i];
System.out.println("Name : " + name);
 
Harry
-----

    following servlet gives a errornull message. Please help me to overcome.
     
    Regards
    Nilantha
     
     
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;

     
    public class cartExample extends HttpServlet{
        HttpSession session = null;
       
        public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
            try {response.setContentType("text/html");
            PrintWriter out = new PrintWriter (response.getOutputStream());
            out.println("<html>");
            out.println("<head><title>Servlet</title></head>");
            out.println("<body>");
            out.println ("Here are the ordered Items");
            
            session = request.getSession(true);
           
            Integer itemcount = (Integer) session.getValue("itemcount");
           
            if (itemcount == null){
                itemcount = new Integer(0);
            }
           
            String [] selected = request.getParameterValues("item");
            System.out.println (selected.length);
            if (selected != null){
                for (int i= 0; i<selected.length; i++){
                    if (selected[i]!=null){
                        String name = selected [i];
                        System.out.println ("not null");
                        itemcount = new Integer (itemcount.intValue()+1);
                        session.putValue(Integer.toString(i).trim(),new String(name));
                    }
                }
                         
                session.putValue("item count", itemcount);
            }
           
            System.out.println (itemcount.intValue());
            out.println("The products are");
            for (int i=0; i <itemcount.intValue(); i++){
                if (session.getValue(Integer.toString(i).trim())!=null){
                    String item = (String) session.getValue(Integer.toString(i).trim());
                    out.print ("<p>" + item);
                }
            }
            out.println ("</body></html>");
            out.close();
        }
       
        catch(Exception e){
            System.out.println ("error" + e.getMessage());
        }
    }
        public void destroy (){
            session = null;
        }
    }

Reply via email to