java_天照 2013-12-25 15:08 采纳率: 33.3%
浏览 2523
已采纳

SpringMVC+hibernate4+Extjs4.2+mysql(空指针异常)

@ResponseBody
@RequestMapping("/daochu.do")
public Object daochu(String id,HttpServletRequest request)throws Exception{
String ids=id.replaceAll(",", "','");
//System.out.println(ids);
//根据两个id同时查询两条语句
String hql="FROM WorkOrders WHERE id IN ('"+ids+"')";
//String hql="FROM WorkOrders w where w.id=?";
//System.out.println(ids);
System.out.println(id);
Query query=sessionFactory.openSession().createQuery(hql);
//query.setString(0, id);
List list=query.list();
Iterator i=list.iterator();
Workbook wb=new HSSFWorkbook();
Sheet sheet=wb.createSheet("第一个sheet页");
int m=0;
int n=0;
while(i.hasNext()){
WorkOrders user = (WorkOrders) i.next();
Row row=sheet.createRow(m);
Cell cell1=row.createCell(0);
Cell cell2=row.createCell(1);
Cell cell3=row.createCell(2);
Cell cell4=row.createCell(3);
Cell cell5=row.createCell(4);
Cell cell6=row.createCell(5);
Cell cell7=row.createCell(6);
cell1.setCellValue(user.getId());
cell2.setCellValue(user.getFailuretime());
cell3.setCellValue(user.getFailureaddress());
cell4.setCellValue(user.getRepairtime());
cell5.setCellValue(user.getMaintenanceman());
cell6.setCellValue(user.getCompletion());
cell7.setCellValue(user.getFailurecontent());
m++;
}
String fileName="sss.xls";
String path=request.getSession().getServletContext().getRealPath("/")+"file"+"\"+fileName;// .servletContext.getRealPath("");
System.out.println(path);
//在该位置导出excel文件
//F:\lr_space.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\SpringMVC2\file
FileOutputStream fileOut=new FileOutputStream(path);
wb.write(fileOut);
fileOut.close();
return "success";
}


前台的页面Extjs
export_Item:function(button){
var grid=button.up('globalStatisticsView')
var data =grid.getSelectionModel().getSelection();
if(data.length==0){
Ext.Msg.alert("提示","您至少选择一条数据")
}else{
//1.先得到ID的数据(name)
var st=grid.getStore();
var ids=[];
Ext.Array.each(data,function(record){
ids.push(record.get('id'));
});
//2.后台操作
Ext.Ajax.request({
params:{ids:ids.join(",")},
url:'gdgl/daochu.do?id='+ ids,
method:'POST',
timeout:2000,
async:false,
success:function(response,opts){
Ext.Array.each(data,function(record){
st.getById(record);
//st.removeAll(record);
});
}

                    });
                    Ext.Msg.alert("报表成功导出","<font color='green'>报表导出成功!谢谢!<font>");
                }
    },

报出的异常错误是:
5,6
十二月 25, 2013 10:57:36 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet spring threw exception
java.lang.NullPointerException
at cn.com.cisec.hnjt.control.WorkOrdersController.daochu(WorkOrdersController.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)


还有火狐调试的时候发现POST传值去后台时会发生
POST daochu.do?id=5,6 500 Internal Server Error 127.0.0.1:8080 3.4 KB 127.0.0.1:8080

  • 写回答

1条回答

  • java_天照 2013-12-26 08:24
    关注

    我知道了,我的sessionFactory没有注入
    我的session也没有注入

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏