请问怎么才能把a对象中的值输出?
Integer a=(Integer)session.getAttribute("MyCount");如果用以下形式
int a=((Integer)session.getAttribute("MyCount")).intValue();
out.print(a);
系统报错,请问怎么处理?

解决方案 »

  1.   

    int a=Integer.parseInt(session.getAttribute("MyCount"));
      

  2.   

    不行啊,报下面的错误,是不是要引入其它的包?C:\Tomcat 4.1\work\Standalone\localhost\_\_4_17MessInput_jsp.java:77: cannot resolve symbol
    symbol  : method parseInt (java.lang.Object)
    location: class java.lang.Integer
    int a=Integer.parseInt(session.getAttribute("MyCount"));
      

  3.   

    int a=Integer.parseInt(session.getAttribute("MyCount"));
    这个市可以的 不需要引入其他的包
      

  4.   

    忘了提了,MyCount里放的是Integer类的对象
    Integer myCount=(Integer)application.getAttribute("Count");
    session.setAttribute("MyCount",myCount);
      

  5.   

    忘了提了,MyCount放的是Integer类型的对象
    Integer myCount=(Integer)application.getAttribute("Count");
    session.setAttribute("MyCount",myCount);
    。Integer a=(Integer)session.getAttribute("MyCount");
      

  6.   

    String a=(String)session.getAttribute("MyCount");
      int b = Integer.parseInt(a);
    这样试试
      

  7.   

    String a=(String)session.getAttribute("MyCount");
      int b = a.intValue();
      

  8.   

    错了错了
    Integer a=(Integer)session.getAttribute("MyCount");
     int b = a.intValue();
      

  9.   

    int a=Integer.parseInt(session.getAttribute("MyCount").toString());
      

  10.   

    Integer myCount=(Integer)application.getAttribute("Count");
    session.setAttribute("MyCount",myCount);汗 
    int myCount==application.getAttribute("Count");session.setAttribute("MyCount",myCount+"");int a=Integer.parseInt(session.getAttribute("MyCount").toString());
      

  11.   

    系统报的什么错?你确定myCount对象有值吗?只要有值System.out.println(((Integer)session.getAttribute("MyCount")).intValue())就会打印出值来,如果你的myCount对象是Null的话就会出现转换异常.
      

  12.   

    可能一开始加载MyCount时没有值
      

  13.   

    报以下错误
    org.apache.jasper.JasperException
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)java.lang.NullPointerException
    at org.apache.jsp._4_17MessInput_jsp._jspService(_4_17MessInput_jsp.java:78)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      

  14.   

    测试后,应该是MyCount对象没有值,但是我觉得我的代码没有问题,不知道错在那里?各位大侠能帮我看看,我这个代码主要是用来网络客户计数用的
    <%!
         synchronized void countPeople() 
    {   
    ServletContext application=getServletContext();
         Integer number=(Integer)application.getAttribute("Count");
    if (number==null)
    {
    number=new Integer(1);
    application.setAttribute("Count",number);
    }
    else{
    number=new Integer(number.intValue()+1);
    application.setAttribute("Count",number);
    }
    }
    %>
    <%   
    if (session.isNew())
    {
    countPeople();
    Integer myCount=(Integer)application.getAttribute("Count");
    session.setAttribute("MyCount",myCount);
    }
    %>
    <% 
    int a=((Integer)session.getAttribute("MyCount")).intValue();
             out.print(a);
    %>
      

  15.   

    把Integer number=(Integer)application.getAttribute("Count");
    改为
    Integer number=  null==application.getAttribute("Count")?null:(Integer)application.getAttribute("Count");再试试
      

  16.   

    还有,你用的变量名字好像是保留字,最好不要用application做你自己变量的名字吧。
      

  17.   

    Integer a=(Integer)session.getAttribute("MyCount");
    out.print(a);
    直接输出就可以