请问怎么才能把a对象中的值输出?
Integer a=(Integer)session.getAttribute("MyCount");如果用以下形式
int a=((Integer)session.getAttribute("MyCount")).intValue();
out.print(a);
系统报错,请问怎么处理?
Integer a=(Integer)session.getAttribute("MyCount");如果用以下形式
int a=((Integer)session.getAttribute("MyCount")).intValue();
out.print(a);
系统报错,请问怎么处理?
symbol : method parseInt (java.lang.Object)
location: class java.lang.Integer
int a=Integer.parseInt(session.getAttribute("MyCount"));
这个市可以的 不需要引入其他的包
Integer myCount=(Integer)application.getAttribute("Count");
session.setAttribute("MyCount",myCount);
Integer myCount=(Integer)application.getAttribute("Count");
session.setAttribute("MyCount",myCount);
。Integer a=(Integer)session.getAttribute("MyCount");
int b = Integer.parseInt(a);
这样试试
int b = a.intValue();
Integer a=(Integer)session.getAttribute("MyCount");
int b = a.intValue();
session.setAttribute("MyCount",myCount);汗
int myCount==application.getAttribute("Count");session.setAttribute("MyCount",myCount+"");int a=Integer.parseInt(session.getAttribute("MyCount").toString());
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)
<%!
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);
%>
改为
Integer number= null==application.getAttribute("Count")?null:(Integer)application.getAttribute("Count");再试试
out.print(a);
直接输出就可以