<html>
<head>
<title>文件上传</title>
</head>
<body>
<form action="uploade.do" method="POST"
enctype="multipart/form-data"
>
文件:<input type="file" name="fileInfo"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>
ServletContext sc = this.servlet.getServletContext();
//将站点下的目录的相对路径,改为基于操作系统盘符的 绝对路径
String filePath = sc.getRealPath("/uploadFile");
String fileName = filePath +"/" + ff.getFileName();
//保存到数据库中
String saveFileName = "uploadFile/" + ff.getFileName();
-------------------------------------文件下载Excel
public ActionForward WriteMulExcle(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
String yearName = request.getParameter("yearName");
String monthName = request.getParameter("monthName");
if(yearName==null||"".equals(yearName)||monthName==null||"".equals(monthName)){
yearName=(String) request.getSession().getAttribute("yearName");
monthName=(String) request.getSession().getAttribute("monthName");
}
Object obj = (Object) request.getSession().getAttribute("ExcelMulDc");
response.setContentType("application/vnd.ms-excel");
String downLoadFileName = "综合分析报表.xls";
try {
downLoadFileName = URLEncoder.encode(downLoadFileName, "utf-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
response.addHeader("Content-Disposition","attachment;filename="+downLoadFileName);
OutputStream os=null;
DetachedCriteria dc = null;
try {
os = response.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
if(obj==null){
dc = DetachedCriteria.forClass(EleMonth.class);//
addEleMonthYear(yearName, dc);
addEleMonthMonth(monthName, dc);
addOrder(dc);
}else{
dc = (DetachedCriteria) obj;
}
List<EleMonth> muls = HibernateUtil.excuteDetachedCriteria(dc);
new JXLUtil_Mul().WriteExcel(muls,os,yearName,monthName);
return null;
}