java后台代码:
public void download(){
String downloadName="teachers.xls";
List<Teachers> tList=tService.getAllTeachersExcel();
try {
PoiUtils poiUtils = new PoiUtils();//Excel工具类
HttpServletResponse response = getResponse();
response.setCharacterEncoding("UTF-8");//设置响应的字符编码格式
response.setContentType("application/vnd.ms-excel");//指明响应文件为excel类型
response.setHeader("Content-disposition", "attachment;filename="+ new String(downloadName.getBytes("GB2312"), "ISO8859-1"));//文件名编码处理,防止浏览器下载文件名乱码
ServletOutputStream outputStream =response.getOutputStream();//获取响应的字节输出流
String[] headers = {"教师编号","教师卡号","教师名称","教师性别"};
poiUtils.createExcel(tList, Teachers.class, outputStream,headers);
} catch (IOException e) {
e.printStackTrace();
}//文件名编码处理,防止浏览器下载文件名乱码
renderNull();
}
EasyUI前端代码:
function downloadInfo() {
$.messager.confirm("提示信息", "你确定要导出所有数据吗?", function(r) {
if(r) {
window.location.href = "http://localhost:8080/JFinalResSta/tc/download";
}
});
}
报错:
十月 12, 2018 2:36:12 下午 com.jfinal.core.ActionHandler error
SEVERE: /tc/download
java.lang.RuntimeException: dao 只允许调用查询方法
at com.jfinal.plugin.activerecord.DaoContainerFactory$DaoMap.entrySet(DaoContainerFactory.java:94)
at com.jfinal.plugin.activerecord.Model.toString(Model.java:791)
at java.lang.String.valueOf(String.java:2854)
at com.yyc.tools.PoiUtils.getFieldValue(PoiUtils.java:291)
at com.yyc.tools.PoiUtils.createRowData(PoiUtils.java:218)
at com.yyc.tools.PoiUtils.createWorkbook(PoiUtils.java:180)
at com.yyc.tools.PoiUtils.createExcel(PoiUtils.java:124)
at com.yyc.controller.TeacherController.download(TeacherController.java:147)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
at com.yyc.Interceptor.GlobalActionInterceptor.intercept(GlobalActionInterceptor.java:24)
at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:365)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
十月 12, 2018 2:36:12 下午 com.jfinal.core.JFinalFilter error
SEVERE: /tc/download
java.lang.IllegalStateException: STREAM
at org.eclipse.jetty.server.Response.getWriter(Response.java:699)
at com.jfinal.render.ErrorRender.render(ErrorRender.java:59)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:137)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:365)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
大概原因知道,是因为jfinal自动生成实体类缺少get方法导致的,怎么能解决?