业务的数据大部分还是手工数据,但是大屏的数据需要日常维护,为了方便业务,制作文件上传功能
直接上传表格文件到服务器,把Excel作为数据集使用,入库且展示,本文是windows服务器
1.服务器编写jsp文件
需要注意的是存放jsp文件的路径,帮助文档给的是
http://www.finereporthelp.com:8181/apptest/download.jsp,因人而异
详细见
https://help.fanruan.com/finereport/doc-view-1938.html
我这边是tomcat做了虚拟目录的,E:\webroot就是跟tomcat绑定了
jsp代码如下
<%@ page contentType="application/vnd.ms-excel" language="java" import="java.io.*" pageEncoding="GBK"%>
<%
response.reset();
response.setContentType("application/x-download");
String fileid=request.getParameter("id");
if(fileid==null) fileid="";
String path = "e:/webroot/测试.xlsx";
String downloadname = "ceshi.xlsx";
response.addHeader("Content-Disposition","attachment;filename=" + downloadname);
java.io.OutputStream outStream = null;
java.io.FileInputStream in = null;
try
{
outStream = response.getOutputStream();
in = new FileInputStream(path);
byte[] b = new byte[1024];
int i = 0;
while((i = in.read(b)) > 0)
{
outStream.write(b, 0, i);
}
outStream.flush();
out.clear();
out = pageContext.pushBody();
}
catch(Exception e)
{
System.out.println("Error!");
e.printStackTrace();
}
finally
{
if(in != null)
{
in.close();
in = null;
}
}
%>
有个点需要注意
String path = "e:/webroot/测试.xlsx";
String downloadname = "ceshi.xlsx";
第一个是上传之后的文件名称,要和你上传的文件名称对应,中英文都可以,但是下载名称必须是英文!!!不可以是中文,否则会访问失败!!!
2.文件上传
在模板的填报属性里添加自定义提交
确保文件名称可以对应上
3.远程连接
新建文件数据集,选择url,然后测试链接,弹出成功
url就和上上边说的,我的webroot做了虚拟目录,所以直接
down.jsp是jsp文件名,可以浏览器直接访问这个连接,如果可以下载刚刚上传的Excsl文件就没问题
预览出数据,尽量不要在上传的文件里使用公式