错误信息
--------------------------------------------------------------------------------type Exception reportmessage 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
javabean.Pool.setaml(Pool.java:111)
org.apache.jsp.country_jsp._jspService(country_jsp.java:73)
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.28 logs.
--------------------------------------------------------------------------------type Exception reportmessage 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
javabean.Pool.setaml(Pool.java:111)
org.apache.jsp.country_jsp._jspService(country_jsp.java:73)
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.28 logs.
if(!request.getParameter("code").equals("")){
String code=request.getParameter("code");//代码
String cname=request.getParameter("cname");//名称
db.setaml(code,cname);//添加“代码"和“名称"到 Hashmap中
}
}
我認爲你這塊寫的有問題!非要這麽些嗎?
public class Pool{
private HashMap aml=null;//无空间
public void setaml(String code,String name){
aml.put(code,name);//使用aml
}
public HashMap getaml(){
return aml;
}
}
既然aml=null那使用aml.put();当然会出现NullPoint了,aml为空呀!!!!!一定要把aml指向一个引用才可以使用aml的方法!!!!
request.getParameter("code")!=null 所以不会去后面.equals("")啊!就不会抛出nullpoint了
这个nullpoint到底是哪个造成的,还应该好好调查一下阿,把变量都打出来看一下哈!
至少应该这样吧
db为空??cname为空??
HashMap aml=new HashMap();
至少应该这样吧
谢谢你
HashMap hm=db.getaml();
Set set=hm.keySet();
Iterator it=set.iterator();
while(it.hasNext()){
String code=(String)it.next();
String value=(String)hm.get(code);
out.println(code+":"+value);
}
我想在另一个界面想得到里面的数据,怎么没有记录
改成
private HashMap aml=new HashMap();
db.setaml(code,cname);//添加“代码"和“名称"到 Hashmap中
就不会出现NullPointException了.
HashMap hm=db.getaml();
Set set=hm.keySet();
Iterator it=set.iterator();
while(it.hasNext()){
String code=(String)it.next();
String value=(String)hm.get(code);
out.println(code+":"+value);
}
我想在另一个界面想得到里面的数据,怎么没有记录
Set set=hm.keySet();
Iterator it=set.iterator();
while(it.hasNext()){
String code=(String)it.next();
String value=(String)hm.get(code);
out.println(code+":"+value);
}
我想在另一个界面想得到里面的数据,怎么没有记录
然后在读取页面request.getAttribute("db");//值为Object类型
强制类型转换后就可以用了.