Excel 내보내기, 이 페이지를 가리키기만 하면 몇 개의 인자를 설정하면 내보내기

<%@ page contentType="application/vnd.ms-excel;charset=GBK"%>
<%@ page import="com.isoftstone.util.poi.*"%>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.poi.hssf.usermodel.*"%>
<%@ page import="java.io.*"%>

<%
			ExcelParameterInterface excelParam = (ExcelParameterInterface) request.getSession()
					.getAttribute("EXCELPARAM");
			if (excelParam == null) {
				throw new RuntimeException(" .");
			}
			response.reset();
			response.setContentType("application/vnd.ms-excel;charset=GBK");
			String fileName = excelParam.getFileName();
			response.setHeader("Content-Disposition", "attachment; filename="
					+ fileName + ".xls");

			OutputStream httpOut = response.getOutputStream();

			List dataTitle = excelParam.getDataHead();
			List dataDetail = excelParam.getDataDetail();
			try {
				HSSFWorkbook wb = ExcelSimple.createWorkbook();
				ExcelSimple excelSimple = new ExcelSimple(); 
				excelSimple.insertRowsOneSheel(wb, dataTitle, dataDetail);
				
				wb.write(httpOut);
				httpOut.close();
			} catch (Exception ex) {
				response.setContentType("text/html");

				out.println("<html>");
				out.println("<head>");
				out.println("<title> </title>");
				out
						.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">");
				out.println("</head>");

				out.println("<body bgcolor=\"white\">");

				out.println("<span class=\"bnew\">  :</span>");
				out.println("<pre>");

				ex.printStackTrace();

				out.println("</pre>");

				out.println("</body>");
				out.println("</html>");

				return;
			}
		%>

위에 JSP 코드가 있어요.
|
|
|
|
다음은 Action의 코드입니다.
       List resultList = new Vector();// , 
        
        List titleList = new Vector();// 
          // 
            ExcelParameterInterface excelParam = new ExcelParam("exportReport",
                    titleList, resultList);
            request.getSession().setAttribute("EXCELPARAM", excelParam);
            request.setAttribute("reportList", reportList);
            response.sendRedirect(request.getContextPath()
                    + "/excelexport/excelexport.jsp");
            return mapping.findForward("");
        }
        else
        {
            request.setAttribute("wrongPrompt1", " ");// , 
        }
        return mapping.findForward("success");

좋은 웹페이지 즐겨찾기