직장에서 일하고 있습니다. 회사의 모든 팀에게해야 할 일에 대한 개요를 제공하는 GWT 응용 프로그램에서 작업하고 있습니다. 프로그램이 작동하지만 이제 우리는 다운로드 할 수있는 Excel 테이블이 * .xlsx가되고 xls가 아님을 확인합니다. 이 전체 프로젝트는 새로운 것이므로 GWT 초보자라고 생각합니다.GWT 다운로드 Excel .xlsx가 손상된 파일을 제공합니다.
Exceltable에 파일 이름이 주어지면 코드 끝에 + .xls가 있습니다. 그러나 "+ xlsx"로 변경하고 응용 프로그램을 테스트해도 다운로드는 계속되지만 Excel에서 파일을 열려고하면 오류 메시지가 나타나고 파일이 손상되었다고 알려줍니다. (.xls 작동)
GWT에서 serverSite 생성 된 Excel로 다운로드하는 방법을 설명해 주시겠습니까? 은 아마 당신은 를 손상 할 수있는 파일의 원인을 몇 가지 아이디어 (내가 물어 보지 수 슬프게도이 어플의 프로그래머가 휴일에를 ...) 미리
감사를
편집 :
public class Download extends HttpServlet {
private static final long serialVersionUID = 5580666921970339383L;
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String filename = (String)request.getSession().getAttribute(CrossReportConstants.ATTR_FILENAME);
byte[] data = (byte[])request.getSession().getAttribute(CrossReportConstants.ATTR_REPORT);
request.getSession().setAttribute(CrossReportConstants.ATTR_FILENAME, null);
request.getSession().setAttribute(CrossReportConstants.ATTR_REPORT, null);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=" + filename);
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setContentLength(data.length);
try {
InputStream in = new ByteArrayInputStream(data);
ServletOutputStream out = response.getOutputStream();
byte[] outputByte = new byte[4096];
// copy binary contect to output stream
while (in.read(outputByte, 0, 4096) != -1) {
out.write(outputByte, 0, 4096);
}
in.close();
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
당신이 코드를 제공 한
변경할 코드를 제공 할 수 있습니까? http 응답에서 파일의 이름을 변경하는 것 같지만 콘텐츠 유형은 변경되지 않은 것 같습니다. – Akkusativobjekt
@Akkusativobjekt 문제는 여기에 코드를 게시하는 것이 허락되지 않았습니다 .... 그리고 전체 프로젝트는 상대적으로 크고 80 개 이상의 클래스를 가졌으며 순간적으로 저는 뭔가를 바꿔야한다는 것을 알기 위해 노력하고 있습니다 .... 슬프게도 그가 휴일 때문에 .... 동료에게 물어볼 수 없습니다. 코드 부분을 찾으면 그것을 공유 할 것입니다 – KilledByCheese
HttpServlet이 response.setContentType ("application/vnd.ms-excel")과 같은 것을 찾는다면; – Akkusativobjekt