JSP 에서 Excel 표 의 인 스 턴 스 를 내 보 냅 니 다.

2194 단어 jsp도 출Excel 표
자바 배경 에서 Model AndView 대상 을 되 돌려 주 고 이 두 줄 설정 을 추가 합 니 다.

response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition","attachment;filename=" + URLEncoder.encode("    .xls", "UTF-8"));
이 두 줄 을 JSP 에 넣 을 수도 있어 요.
jsp 코드 는 다음 과 같 습 니 다:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
 response.setContentType("application/vnd.ms-excel");
 response.setHeader("Content-disposition","attachment;filename=" + java.net.URLEncoder.encode("    .xls", "UTF-8"));
%>
<!DOCTYPE html>
<html>
<head>
 <title>CMS-    </title>
 <meta charset="utf-8" />
 <meta http-equiv="pragma" content="no-cache"/>
 <meta http-equiv="cache-control" content="no-cache"/>
 <meta http-equiv="expires" content="0"/>
</head>
<body>

<table id="sample-table-1" border="1" cellpadding="2" cellspacing="1">
 <thead>
 <tr>
  <th nowrap width="15%">  </th>
  <th nowrap width="5%">  </th>
  <th nowrap width="5%">  </th>
  <th nowrap width="5%">  </th>

 </tr>
 </thead>
 <tbody>
 <c:forEach items="${list}" var="model" varStatus="status" >
  <tr>
   <td>${model.id}</td>
   <td>${model.cardNo}</td>
   <td>${model.name}</td>
   <td>${model.age}</td>
  </tr>
 </c:forEach>
 </tbody>
</table>
</body>
</html>
이상 의 JSP 에서 엑셀 표를 내 보 낸 실례 는 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.여러분 에 게 참고 가 되 고 여러분 들 이 저 희 를 많이 지지 해 주시 기 바 랍 니 다.

좋은 웹페이지 즐겨찾기