[Jsp] Jsp 엑셀 다운로드

2014. 3. 31. 13:44프로그래밍/Jsp


1. Jsp 에서 엑셀 다운로드 하기

=========================================================================================================

================================================List.jsp==================================================

=========================================================================================================

<html>

<head>

<title>엑셀 다운로드 Test</title>

<script type="text/javascript">

function excelDown(){

var f = document.form1;

f.action="/test/downList.jsp";

f.submit();

}

</script>

</head>

<body>

<form name="form1" method="post">

<table border="1">

<thead>

<tr>

<th>번호</th>

<th>제목</th>

<th>작성자</th>

</tr>

</thead>

<tbody>

<tr>

<td>1</td>

<td>테스트</td>

<td>홍길동</td>

</tr>

</tbody>

</table>

<input type="button" value="excelDown" onClick="excelDown()" />

</form>

</body>

</html>


=========================================================================================================

=============================================downList.jsp================================================

=========================================================================================================


<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>엑셀 다운로드</title>

</head>

<body>

<%

response.setContentType("application/vnd.ms-excel");

response.setHeader("Content-Disposition", "inline; filename=excelDown.xls");

%>

<table border="1">

<thead>

<tr>

<th>번호</th>

<th>제목</th>

<th>작성자</th>

</tr>

</thead>

<tbody>

<tr>

<td>1</td>

<td>테스트</td>

<td>홍길동</td>

</tr>

</tbody>

</table>

</body>

</html>