📄 importreportieservlet.java
字号:
package com.glf.reportIE.servlet;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.glf.reportIE.commons.*;
public class ImportReportIEServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
//PrintWriter out = response.getWriter();
//HttpSession session=request.getSession();
String screen=request.getServletPath();
if(screen.equals("/pages/reportIE/checkReportIE"))
{
String errorMessage="";
String forwardPage="chooseImportExcel.jsp";
try
{
SmartUpload _mySmartUpload = new SmartUpload();
_mySmartUpload.initialize(getServletConfig(), request, response);
_mySmartUpload.setAllowedFilesList("xls");
_mySmartUpload.upload();
SmartFile _mySmartFile = _mySmartUpload.getFiles().getFile(0);
//String excel_name = _mySmartFile.getFileName();
String excel_name = _mySmartUpload.getRequest().getParameter("hiddenFormName")+".xls";
StringBuffer excelPath = new StringBuffer();
excelPath.append((getServletConfig().getServletContext().getRealPath("")));
excelPath.append("/pages/reportIE/model/"+excel_name);
_mySmartFile.saveAs(excelPath.toString());
errorMessage = "【"+excel_name+"】文件上传成功!";
}
catch (Exception e)
{
if(e.getMessage().equals("File can't be saved (1120)."))
{
errorMessage="文件存储失败:通知管理员审查路径权限 或稍后重试!";
}
if(e.getMessage().equals("The extension of the file is not allowed to be uploaded (1010)."))
{
errorMessage="文件选择错误:请检查选择的文件,只能选择后缀名为xls的excel文件!";
}
}
request.setAttribute("errorMessage", errorMessage);
request.getRequestDispatcher(forwardPage).forward(request,response);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -