앱)java spring framework excel export jstl
<a href="#" class="com_s_excel" onclick="exportExcel();"><span>Export to Excel</span></a>
function exportExcel(){
$("searchForm").attr("action","<c:url value='/exportExcel.do' />").submit();
}
@RequestMapping(value="/exportExcel", method= RequestMethod.POST)
public ModelAndView exportExcel(HttpServletRequest request, HttpServletResponse response, @ModelAttribute SearchVo searchVo){
ModelAndView view = new ModelAndView();
view.addObject("contents", ServiceObj.getExportExcel(searchVo);
view.setViewName("/exportExcel");
return view;
}
====exportExcel.jsp
<%@ page language="java" contentType="application/vnd.ms-excel; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
response.setHeader("Content-Type", "application/vnd.ms-xls");
response.setHeader("Content-Disposition", "inline; filename=ExportList.xls");
%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>td { mso-number-format:\@; } </style>
</head>
<body>
<table style="text-align:center; font-weight:normal; background:#fafafa; color:#333; font-size:12px; border:1px solid #CCC;">
<caption class="hide-caption">List</caption>
<thead>
<tr style="border:1px solid #CCC; color:#555">
<th scope="col"><span class="sort" id="id">ID</span></th>
<th scope="col"><span class="sort" id="id">ID</span></th>
</tr>
</thead>
<tbody>
<c:choose>
<c:when test="${null != contents && !empty contents}">
<c:forEach var="contents" items="${contents}" varStatus="lineIndex">
<tr style="padding:8px; line-height:16px; border:1px solid #CCC; color:#555; font-size:12px; vertical-align:middle; word-break:break-all;">
<td class="al_c">${contents.code}</td>
<td class="al_c">${contents.name}</td>
<td class="al_c">${contents.desc}</td>
<td class="al_c">${contents.code1}</td>
<td class="al_c">${contents.code2}</td>
<td class="al_c">${contents.code2}</td>
<tr>
</c:forEach>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
</tbody>
</table>
</body>
</html>
'백엔드개발 > 자바스프링' 카테고리의 다른 글
앱)jstl list search result table sample 예제 (0) | 2018.06.12 |
---|---|
앱)jstl sample 예제 (0) | 2018.06.12 |
앱)jsp jstl jquery basic structure sample 기본 템플릿 (0) | 2018.06.11 |
앱)java springframework select box jstl form sample 예제 (0) | 2018.06.11 |
앱)logback 한줄 로그 나오게 하는 방법 (0) | 2018.06.08 |