message description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.lang.NullPointerException
java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:980)
java.lang.Float.valueOf(Float.java:205)
com.cart.processRequest(cart.java:32)
org.apache.jsp.cart_jsp._jspService(cart_jsp.java:82)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.0.27

解决方案 »

  1.   

    那你用hashmap试试,他们之间的区别只有,key值hashtable不能为空,hashmap可以为空
      

  2.   

    NullPointerException
    空指针,看看有什么对象可能为空却没有判断
      

  3.   

    购物车bean源码如下(cart.java)
    package com;import java.util.*; 
    import com.msgCart;
    import javax.servlet.http.*;
    public class cart{ 
        
        public Hashtable items; 
        
        public void processRequest(HttpServletRequest clientRequest)
       {
       String id,name,pri,pri1,submit,strNumber;
       int number;
       float price,price1;
       //取得客户端数据
       submit=clientRequest.getParameter("submit");
      
                    id=clientRequest.getParameter("id");
       strNumber=clientRequest.getParameter("strNumber");
       pri=clientRequest.getParameter("price");
                    pri1=clientRequest.getParameter("price1");
       name=clientRequest.getParameter("name");
                    
                    price=(Float.valueOf(pri)).floatValue();
                    price1=(Float.valueOf(pri1)).floatValue();
       number=(Integer.valueOf(strNumber)).intValue();
                    
                    
                    
                    //点击"clear"按钮的情况
       if(submit!=null)
       {
       if(submit.equals("clear"))
       {
       clear();
       return;
       }                                                  //点击"add"按钮的情况
                             if(submit.equals("add"))
                             {                              
                                  add(id,number,price,price1,name);
                                  //return;
                             }
      
                             //点击"remove"按钮的情况
                             if(submit.equals("remove"))
                             {
                                remove(id);
                             }
      
                                //点击"update"按钮的情况
                             if(submit.equals("update"))
                             {
                                update(id,number);
                             }
          }
        
                    
                    
                } 
        
        
    (msgCart.java)
    package com;
    import java.util.*; public class msgCart 

        
        public int pro_count=0;
        public float price=0;
        public float price1=0;
        public String id;
        public String pro_name;
             public msgCart()
        {
           
        }    public void setCart(String id,int number,float price,float price1,String name)    
        {
          this.pro_count=number;
          this.price=price;
          this.price1=price1;
          this.id=id;
          this.pro_name=name;
          
        }         public void addPro(int pc)             //添加商品
        {
            pro_count+=pc;
        }     public void modPro(int mc)            //修改商品数量
        {
            pro_count=mc;
        }         public String getId()                 //返回产品的ID号
        {
            return id;
         }     public int getProcount()           //返回产品的定购数量
        {
            return pro_count;
        }             public float getPrice()             //返回产品原价
        {
            return price;
         }     public float getPrice1()            //返回产品现价
         {
            return price1;
         }      public float getPricecount()         //返回每个产品的订购总价(以现价为准)。
        {
            return price1*pro_count;
        }     public String getProname()           //返回每个产品的名字。
        {
            return pro_name;
        }
       
          }
      

  4.   

    上边的(cart.java)没贴全重贴如下
    package com;import java.util.*; 
    import com.msgCart;
    import javax.servlet.http.*;
    public class cart{ 
        
        public Hashtable items; 
        
        public void processRequest(HttpServletRequest clientRequest)
       {
       String id,name,pri,pri1,submit,strNumber;
       int number;
       float price,price1;
       //取得客户端数据
       submit=clientRequest.getParameter("submit");
      
                    id=clientRequest.getParameter("id");
       strNumber=clientRequest.getParameter("strNumber");
       pri=clientRequest.getParameter("price");
                    pri1=clientRequest.getParameter("price1");
       name=clientRequest.getParameter("name");
                    
                    price=(Float.valueOf(pri)).floatValue();
                    price1=(Float.valueOf(pri1)).floatValue();
       number=(Integer.valueOf(strNumber)).intValue();
                    
                    
                    
                    //点击"clear"按钮的情况
       if(submit!=null)
       {
       if(submit.equals("clear"))
       {
       clear();
       return;
       }                                                  //点击"add"按钮的情况
                             if(submit.equals("add"))
                             {                              
                                  add(id,number,price,price1,name);
                                  //return;
                             }
      
                             //点击"remove"按钮的情况
                             if(submit.equals("remove"))
                             {
                                remove(id);
                             }
      
                                //点击"update"按钮的情况
                             if(submit.equals("update"))
                             {
                                update(id,number);
                             }
          }  
                    
                    
                }    
        
        
        
        
        public cart()
        {
            items = new Hashtable();
        }      public void add(String id,int number,float price,float price1,String name)
        {
            String ID=new String(id); 
            msgCart m_cart=new msgCart();
            
            if(items.containsKey(ID))
            {   
                m_cart=(msgCart)items.get(ID);
                m_cart.addPro(number);
            }
            else
            {
                 number=1;             
                 items.put(ID,m_cart);
                 m_cart.setCart(id,number,price,price1,name);        
            }    }       public void update(String id,int num)
         {  
             String ID=new String(id);
            if(items.containsKey(ID))
            {     
                msgCart m_cart=new msgCart();
                m_cart=(msgCart)items.get(ID);
                m_cart.modPro(num);
            }
            else
            {
                 System.out.print("no modify pc_count");
             }         }     public void remove(String id)       //删除商品
        {        
            String ID=new String(id); 
            items.remove(ID);
        }       public void clear()              //清空购物车
        {
            items.clear();
        }    
        public Hashtable getCart()   
        {
            return items;
        } 
        public float getCartprice()     //购物车总金额
        {
            Enumeration enum=items.elements();        msgCart m_cart=new msgCart();        float count=0.0f;        while(enum.hasMoreElements())
            {
                m_cart=(msgCart)enum.nextElement();            count+=m_cart.getPricecount();
            }         return count;
         }       }
      
      

  5.   


    jsp页面如下,从其它页面通过url传递参数到这个页面<jsp:useBean id="mycart" class="com.cart" scope="session"/>
    <link href="css.css" rel="stylesheet" type="text/css"> 
     
     <table width="490"  border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#996600" style="border-collapse: collapse">
    <tr>
    <td colspan="8">欢迎!</td>
    </tr>
    <tr>    
        <td width="11%" align="center">商品编码</td>
            <td width="23%" align="center">商品名称</td>
    <td width="11%" align="center">商品单价</td>
            <td width="11%" align="center">订购数量</td>                
            <td width="12%" align="center">修改数量</td>
            <td width="11%" align="center">取消订购</td>
            <td colspan="2" align="center">合计</td>    
    </tr>
    <%
    mycart.processRequest(request);  //从购物车Hashtable中得到一个包含所有商品名称的迭代器Hashtable cart=new Hashtable();
    cart=mycart.getCart(); Iterator ci = cart.keySet().iterator();

    while(ci.hasNext())
    {
    String ID =(String)ci.next();

    if(ID!=null){

    com.msgCart mcart=new com.msgCart();
        mcart=(com.msgCart)cart.get("ID");

    String name =mcart.getProname();
    String id=mcart.getId();
    String price=(String)mcart.getPrice();
    //String price1=(String)mcart.getPrice1();
    //String cartPrice=(String)
    //String proPrice
    }      
    %>


    <tr> 
            <td width="11%" align="center"><%=name%></td>
            <td width="23%" align="center"><%=id%></td>
            <td width="11%" align="center"><%=price%></td>
            <td width="11%" align="center"><input name="Number" type="text" value="strNumber" size="6" align="middle"></td>                
            <td width="12%" align="center"><input type="button" name="Submit" value="update" ></td>
            <td width="11%" align="center"><input type="button" name="Submit" value="delect"></td>
            <td width="18%" align="right"><%%></td>
    <td width="3%" align="right">元</td>           
    </tr>
                 
        <tr>
    <td colspan="8"><table width="100%" cellpadding="0" cellspacing="0" align="center">
    <tr>    
    <td width="75%"  align="right">总计:</td>
    <td width="23%" align="right"><%%></td>
    <td width="2%" align="right">元</td>
    </tr>
     </table></td>
    </tr>
    <%//}%>
    <tr>
    <td colspan="8"><table width="100%" cellpadding="0" cellspacing="0" align="center">
    <tr>
    <td width="33%" align="center"><a href="">继续购物</a></td>
    <td width="34%" align="center">清空购物车</td>
    <td width="33%" align="center"><a href="">前往收银台</a></td>

    </tr>
    </table></td>
    </tr>

    <tr>
    <td colspan="8" align="center"><a href=# onclick="javasrcript:window.close();">关 闭 窗 口</a></td>
    </tr></table>
    <% Enumeration a= request.getParameterNames();
    while(a.hasMoreElements())
    {
      System.out.println(a.nextElement());
    }%>
      

  6.   

    Hashtable不是线程安全的
    Hashmap是线程安全的
    考虑改成那种吧
    其实操作都差不多吧