Title: RE:

errornull is what you are printing when there is no item in either request or session. This is happening because of the System.out.println you are using to print the length of the array. One of the replies for this from Sabari was right. So try calling the servlet with some value already put in the session or with values in the request. Say you can create a html form that submits values to this servlet with a form variable, item holding values for all the items you select. Or you can change the doPost method to service method and try out this sort of URL(which will work regardless of the metod of request): http://localhost:8080/servlet/cartExample?item="one"&item="two"&item="three" .

Regards,
Valavan.

    -----Original Message-----
    From:   Wasala Mudiyanselage Nilantha Piyasiri [SMTP:[EMAIL PROTECTED]]
    Sent:   Thursday, December 13, 2001 1:07 PM
    To:     [EMAIL PROTECTED]
    Subject:       

    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