function fnExcel(){
document.listForm.action="<c:url value='/report.do'/>";
document.listForm.submit();
}
JAVA
@RequestMapping(value="/report.do")
public void report(
@ModelAttribute("reportVo") GameDefaultVo searchVO,
HttpServletRequest request,HttpServletResponse response,ModelMap model)
throws Exception{
List<?> resultList = null;
Calendar dateTime = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String str = formatter.format(dateTime.getTime());
response.reset();
response.setContentType("application/octet-stream");
response.setCharacterEncoding("utf-8");
if(searchVO.getSbscrbSttus().equals("300"))
{
response.setHeader("Content-disposition", "attachment; filename=" + "file"+str+".DAT");
response.setHeader("Content-Type", "text/csv; charset=EUC-KR");
service.reportselect(serchVO, response.getWriter());
}
if(searchVO.getSbscrbSttus().equals("310"))
{
response.setHeader("Content-disposition", "attachment; filename=" + "file"+str+".DAT");
service.reportselect(serchVO, response.getWriter());
}
}
Service
public void reportselect(Writer writer) throws Exception;
ServiceImpl
SuppressWarnings("unchecked")
@Service("ExtnInfReportMngService")
public class ExtnInfReportMngServiceImpl extends AbstractServiceImpl implements ExtnInfReportMngService {
@Resource(name="ExtnInfReportMngDao")
private ExtnInfReportMngDao extnInfReportMngDao;
/** EgovMessageSource */
@Resource(name="egovMessageSource")
EgovMessageSource egovMessageSource;
/** EgovProgrmManageService */
@Resource(name = "ExtnInfReportMngService")
private ExtnInfReportMngService extnInfReportMngService;
public void slrStlInfo(GameDefaultVo searchVO, final Writer writer) throws Exception
{
// extnInfReportMngDao.slrStlInfo(searchVO);
try
{
extnInfReportMngDao.getSqlMapClientTemplate().queryWithRowHandler("ExtnInfReportMngDao.SlrStlInfo", searchVO, new RowHandler()
{
public void handleRow(Object obj)
{
Map<?, ?> hm = (Map<?, ?>)obj;
try
{
writer.write(strPad(String.valueOf(hm.get("ROWNUM")) ,5,"L","0"));
writer.write(strPad(String.valueOf(hm.get("SLR_ID")) ,8,"L","0"));
String str_drno = String.valueOf(hm.get("STL_DRNO"));
if(str_drno.length()==6){
str_drno = str_drno.substring(0,4)+'0'+str_drno.substring(4);
}
writer.write(strPad(str_drno,7,"L","0"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
}
catch(Exception e)
{
throw e;
}
IOUtils.closeQuietly(writer);
}
JSP
<%@ page language="java" contentType="application/vnd.ms-excel; name='excel', text/html; charset=euc-kr" pageEncoding="euc-kr"%><%@ page import="java.util.*,kld.gmn.cmm.utl.fcc.service.EgovStringUtil" %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%><%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %><% response.setHeader("Content-Disposition", "attachment; filename="+request.getAttribute("fileName")); response.setHeader("Content-Type", "application/octet-stream;"); response.setContentType("application/octet-stream; charset=euc-kr");
try {
List rResultList = (List)request.getAttribute("rResultList");
String reportNo = (String)request.getAttribute("reportNo");
for(int iList=0;iList<rResultList.size();iList++){
HashMap hm = (HashMap)rResultList.get(iList);
}else if("310".equals(reportNo)){ //판매인정산대금정보
response.getWriter().write(strPad(String.valueOf(hm.get("ROWNUM")) ,5,"L","0"));
response.getWriter().write(strPad(String.valueOf(hm.get("SLR_ID")) ,8,"L","0"));
response.getWriter().write(strPad(String.valueOf(hm.get("STL_DRNO")) ,7,"L","0"));
}
if(iList < rResultList.size()-1 ) response.getWriter().write("\n");
}
} catch(Exception ex) {
System.out.print("Erro no envio do arquivo");
ex.printStackTrace();
}%><%!
public String strPad(String str,int len,String type,String blank){
try {
int totalByteLength = str.getBytes().length;
int loop = 0;
if(totalByteLength >= len){
return str;
}
else
{
loop = len - totalByteLength;
}
if("L".equals(type))
{
for(int c=0;c<loop;c++){
str = blank + str;
}
}
else if("R".equals(type))
{
for(int c=0;c<loop;c++){
str = str + blank;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
return str;
}%>
'JAVA' 카테고리의 다른 글
java 날짜수계산 질문 드립니다 (0) | 2014.03.27 |
---|---|
JAVA(자바)로 이번주 초와 이번주 말을 찾고싶을때 (0) | 2014.03.27 |
CXF를 이용한 Webservice 서버 구축 (0) | 2014.03.11 |
SoapUI, CXF를 이용한 webservice client 만들기 예제2 (0) | 2014.03.11 |
<JAVA_API> JAVA Program 수행시간 체크 : Time Checking (0) | 2014.03.04 |
[JAVA] 현재 날짜(시간) 구하기 - 월/요일을 한글/영문으로 간단하게 구하기 (0) | 2014.03.04 |
JAVA로 영문 대,소문자+숫자 난수 발생시키기 (0) | 2014.02.28 |
Random 클래스를 이용하여 영문+숫자 랜덤코드 만들기 (0) | 2014.02.28 |