2 lr393993507 lr393993507 于 2013.12.25 23:08 提问

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个回答

lr393993507
lr393993507   2013.12.26 16:24
已采纳

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!