资源简介
javaweb上传下载excel实例
代码片段和文件信息
package com.hzys.excel.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellstyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.hzys.excel.dao.entity.Userinfo;
import com.hzys.excel.service.IUserService;
import com.opensymphony.xwork2.ActionSupport;
@Controller(“userAction“)
@ParentPackage(“struts-default“)
@Namespace(““)
@Scope(“prototype“)
@Action(“userAction“)
public class UserAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
@Resource(name=“userService“)
private IUserService userService;
private Userinfo userinfo;
public String xlsFileName;;
public File xls;
public String docContentType;
public File getXls() {
return xls;
}
public void setXls(File xls) {
this.xls = xls;
}
public String getDocContentType() {
return docContentType;
}
public void setDocContentType(String docContentType) {
this.docContentType = docContentType;
}
public Userinfo getUserinfo() {
return userinfo;
}
public void setUserinfo(Userinfo userinfo) {
this.userinfo = userinfo;
}
public String getXlsFileName() {
return xlsFileName;
}
public void setXlsFileName(String xlsFileName) {
this.xlsFileName = xlsFileName;
}
/*
* 查询所有
*/
public String queryall() throws IOException{
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType(“text/html;charset=utf-8“);
try {
List userlist=userService.queryall();
JSONArray newlist=JSONArray.fromobject(userlist);
response.getWriter().write(newlist.toString());
} catch (Exception e) {
response.getWriter().write(“error“);
}
return null;
}
/*
* 读取excel
*/
public String read() throws Exception IOException{
HttpServletResponse response=ServletActionContext.getResponse();
HttpServletRequest request=ServletActionContext.getRequest();
//获得文件上传的上传目录
String filepath=ServletActionContext.getServletContext().getRealPath(“/filelib“);
//保存文件的文件名称
System.out.println(“文件名字:“+this.getXlsFileName());
String f
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-12-30 10:38 javaWebExcel\
目录 0 2016-12-30 10:38 javaWebExcel\excel\
文件 838 2016-10-18 14:33 javaWebExcel\excel\.classpath
文件 1038 2015-04-16 14:52 javaWebExcel\excel\.project
目录 0 2016-12-30 10:38 javaWebExcel\excel\.settings\
文件 503 2015-04-16 14:52 javaWebExcel\excel\.settings\.jsdtscope
文件 364 2016-10-18 14:33 javaWebExcel\excel\.settings\org.eclipse.jdt.core.prefs
文件 467 2015-04-16 14:52 javaWebExcel\excel\.settings\org.eclipse.wst.common.component
文件 345 2015-04-16 14:52 javaWebExcel\excel\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2015-04-16 14:52 javaWebExcel\excel\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2015-04-16 14:52 javaWebExcel\excel\.settings\org.eclipse.wst.jsdt.ui.superType.name
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\classes\
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\classes\com\
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\classes\com\hzys\
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\classes\com\hzys\excel\
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\classes\com\hzys\excel\action\
文件 8548 2016-10-24 16:09 javaWebExcel\excel\build\classes\com\hzys\excel\action\UserAction.class
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\classes\com\hzys\excel\dao\
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\classes\com\hzys\excel\dao\entity\
文件 1183 2016-10-24 16:09 javaWebExcel\excel\build\classes\com\hzys\excel\dao\entity\Userinfo.class
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\classes\com\hzys\excel\dao\mapper\
文件 427 2016-10-24 16:09 javaWebExcel\excel\build\classes\com\hzys\excel\dao\mapper\UserMapper.class
文件 1443 2015-04-16 14:52 javaWebExcel\excel\build\classes\com\hzys\excel\dao\mapper\UserMapper.xm
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\classes\com\hzys\excel\service\
文件 303 2016-10-24 16:09 javaWebExcel\excel\build\classes\com\hzys\excel\service\IUserService.class
目录 0 2016-12-30 10:38 javaWebExcel\excel\build\classes\com\hzys\excel\service\spring\
文件 1156 2016-10-24 16:09 javaWebExcel\excel\build\classes\com\hzys\excel\service\spring\UserService.class
目录 0 2016-12-30 10:38 javaWebExcel\excel\src\
目录 0 2016-12-30 10:38 javaWebExcel\excel\src\com\
目录 0 2016-12-30 10:38 javaWebExcel\excel\src\com\hzys\
............此处省略118个文件信息
- 上一篇:WeChat.rar
- 下一篇:Android studio百度地图
评论
共有 条评论