struts+ibatis整合开发,查询出的为list的集合,显示在jsp页面,以下拉框形势显示,有没有例子,谁写过我的老获取空值dao:
package com.peak.riskscan.punishment.dao;
import java.sql.SQLException;
import java.util.List;import com.datawise.webframework.core.controller.ActionBase;
import com.datawise.webframework.core.dao.DAO;
import com.datawise.webframework.core.dao.SqlmapDAOHelper;
import com.datawise.webframework.core.model.BeanBase;
import com.peak.riskscan.punishment.action.PunishmentAmtAction;public class PunishmentDao extends SqlmapDAOHelper implements DAO { public void delete(BeanBase model) throws SQLException {
try {
// TODO Auto-generated method stub
this.startTransaction();
executeUpdate("deletePunishment", model);
this.commit();
} catch (SQLException e) {
// TODO: handle exception
System.out.println(e.getMessage());    
//this.rollback();
}
finally {    
            try {    
                this.rollback();    
            } catch (SQLException e) {    
                e.printStackTrace();    
            }    
        }     } public int getCount() throws SQLException {
// TODO Auto-generated method stub
return 0;
} public int getCount(BeanBase bean) throws SQLException {
// TODO Auto-generated method stub
return 0;
} public void insert(BeanBase model) throws SQLException {
// TODO Auto-generated method stub
try {
this.startTransaction();
executeUpdate("insertPunishment", model);
this.commit();
} catch (Exception e) {
// TODO: Auto-generated catch block
e.printStackTrace();
this.rollback();
}
} public List list() throws SQLException {
// TODO Auto-generated method stub
List list = null;
System.out.println("dbxncncnghmhm-------->>>>>>>.");
try {
this.startTransaction();
/*
PunishmentModel pm=new PunishmentModel();
this.getSqlMap().executeQueryForObject("getPunishmentByModel",pm);
Iterator it=null;
while(it.hasNext())
{
System.out.println(pm.getModelName());
System.out.println(pm.getModelDescribe());
}
*/
//list=this.executeQueryForList("getPunishmentByModel",null);
list =(List) this.getSqlMap().executeQueryForList("getPunishmentByModel",null);
int i=list.size();
if(list==null)
{
System.out.println("---------->liu");
}
System.out.println("测试数据输出"+i);


this.commit();
}catch (SQLException e) {
// TODO: handle exception
System.out.println(e.getMessage());    
this.rollback();
}
 
return list;
} public List list(int offset, int limit) throws SQLException {
// TODO Auto-generated method stub
return null;
}
/*
public List query(BeanBase model) throws SQLException {
// TODO Auto-generated method stub
List list = null;
try {
this.startTransaction();
list = this.getSqlMap().executeQueryForList(
"getPunishment", model);
this.commit();
} catch (Exception e) {
// TODO: Auto-generated catch block
e.printStackTrace();
this.rollback();
}
return list;
}
*/

public List query(ActionBase devSample) throws SQLException {
// TODO Auto-generated method stub
List list = null;
try {
this.startTransaction();
list = this.getSqlMap().executeQueryForList(
"getPunishment", devSample);
this.commit();
} catch (Exception e) {
// TODO: Auto-generated catch block
e.printStackTrace();
this.rollback();
}
return list;
}

public BeanBase retrieve(BeanBase model) throws SQLException {
// TODO Auto-generated method stub
return null;
} public int update(BeanBase model) throws SQLException {
// TODO Auto-generated method stub
return 0;
} public List query(BeanBase model) throws SQLException {
// TODO Auto-generated method stub
return null;
} public List query(BeanBase model, int offset, int limit)
throws SQLException {
// TODO Auto-generated method stub
return null;
}}
action:
package com.peak.riskscan.punishment.action;
import java.sql.SQLException;
import java.util.List;import javax.servlet.http.HttpServletRequest;import com.datawise.webframework.IConstants;
import com.datawise.webframework.core.controller.ActionBase;
import com.datawise.webframework.core.controller.ActionEvent;
import com.peak.riskscan.punishment.dao.PunishmentDao;import com.peak.riskscan.punishment.form.PunishmentAmtForm;
import com.peak.riskscan.punishment.form.PunishmentModelForm;
import com.peak.riskscan.punishment.model.PunishmentAmt;
import com.peak.riskscan.query.dao.AtmErrorDAO;
import com.peak.riskscan.query.model.AtmError;
import com.peak.riskscan.query.view.AtmErrorForm;
import com.peak.riskscan.util.BeanUtils;public class PunishmentAmtAction extends ActionBase {

public String onListPunishmentAmt(ActionEvent e) throws SQLException { PunishmentAmtAction devSample = new PunishmentAmtAction();
if (e.getRequest().getParameter("oper") == null
|| !e.getRequest().getParameter("oper").equals("first")) {
PunishmentAmtForm devSampleForm = (PunishmentAmtForm) e.getFormBean();
BeanUtils.populate(devSampleForm, devSample);
}
PunishmentDao devSampleDao = new PunishmentDao();
List list =devSampleDao.query(devSample);

    if(list.size()>0)
    {
     System.out.println("值传过来了");
    }

e.getRequest().setAttribute("dataList", list);
return IConstants.FORWARD_SUCCESS_KEY;
}

//查找出model表信息
public String onListPunishmentModel(ActionEvent e)throws SQLException{
//PunishmentAmtAction devSample1=new PunishmentAmtAction();
//PunishmentModelForm devSampleModelForm=(PunishmentModelForm)e.getFormBean();
//BeanUtils.populate(devSampleModelForm,devSample1);
PunishmentDao  pmd=new PunishmentDao();
List dataList=pmd.list();
e.getRequest().setAttribute("dataList",dataList);

return IConstants.FORWARD_SUCCESS_KEY;

} public String onDeletePunishmentAmt(ActionEvent e) throws Exception { HttpServletRequest request = e.getRequest();
    PunishmentAmt devSample = new PunishmentAmt();
devSample.setModelName(request.getParameter("modelName"));
//devSample.setId(request.getParameter("id"));
PunishmentDao devSampleDao = new PunishmentDao();
devSampleDao.delete(devSample);
return IConstants.FORWARD_SUCCESS_KEY;
} public String onAddPunishmentAmt(ActionEvent e) throws Exception {
PunishmentAmtForm devSampleForm = (PunishmentAmtForm)e.getFormBean();
PunishmentAmt devSample = new PunishmentAmt();
BeanUtils.populate(devSampleForm, devSample);
PunishmentDao devSampleDao = new PunishmentDao();

devSampleDao.insert(devSample);
PunishmentDao  pmd=new PunishmentDao();
List dataList=pmd.list();
if(dataList.size()>0)
    {
     System.out.println("------>>>>>>>>liuuyyyy>>>>>>>>>");
    }

e.getRequest().setAttribute("dataList",dataList);
return IConstants.FORWARD_SUCCESS_KEY;
}}jsp页面:
<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib uri="displaytag" prefix="display" %>
<%@ page import="java.util.*"%>
<%@ page import="com.peak.riskscan.punishment.model.PunishmentModel"%>
<%
     List list=(List)request.getAttribute("dataList");
     int k=list.size();
     System.out.println("---->>>>>>>>>>>>>>"+k);
     PunishmentModel pm=null;
   //  String action ="addPunishmentAmt.do";
      %><script language=javascript src="../../page/javascript/openWin.js"></script>
<script language=javascript src="/RiskScan/page/javascript/popcalendar.js"></script>
<link rel="stylesheet" href="<%=request.getContextPath()%>/page/css/screen.css" type="text/css"><p class="title" align="center">添加处罚金</p>
   
<form method="post" name="QueryForm"  action="<%=request.getContextPath()%>/punishment/addPunishmentAmt.do" >
<table class='simpleform' width="100%">  

<tr>
<td>复核差错与风险预警名:</td>
<td><input type="text" name="modelName"></td>
</tr>
<tr>
<td>处罚金额:</td>
<td><input type="text" name="punishmentAmt"></td>

<td> <select id="modelName">

<%
for(int i=0,j=list.size();i<j;i++)
{
pm=(PunishmentModel)list.get(i);
%>
<option value="<%=pm.getModelName()%>"><%=pm.getModelDescribe()%></option>
<%} %>



</select>


</td>

</tr>
    <td colspan="6" align="center">

<input type="submit"  name="submitbutton" value="确定" title="所输区域记录内容添加至数据库"/>&nbsp;&nbsp;
<input type="reset" value="重置"/>&nbsp;&nbsp;
        <input type="button" value="返回"  onclick="history.back(-2);" title="返回上一页面"/>
        </td>
  </table>
      
     
        
</form>
我的老是空指针异常,弄了一天也没弄好,有例子请告我下

解决方案 »

  1.   

    空指针异常 就是对象没有获取到啊 
    直接点击控制台输出异常信息的类 就知道是
    哪个对像是空了 然后就一步步往上找
    其实最好用debug一调试 马上就知道了
      

  2.   

    伙记.检查一下代码就知道了.从你DAO获得LIST开始一步步把LIST打印出来看看就明白是那儿错了.
      

  3.   

    但是我的dao有问题吗?我觉得是那样写啊,请高人指点