kenu
2001-08-18 03:23:22
0
7328

excel 파일 생성시 한글 코드셋


제가 쓰는 파일 그냥 그대로 올립니다.
브라우저에서 안 띄우고 다운받게 되어있습니다.
tomcat3.1에서 한글도 잘 나옵니다.

<%@ page import="java.sql.*, java.util.*" %><%@ page language="java" contentType="application/vnd.ms-excel;charset=euc-kr" %><%

%><%
// 오늘 날짜
java.text.SimpleDateFormat formatter
= new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String today = formatter.format(new java.util.Date());

String yy = request.getParameter("yy");
yy = (yy==null)?today.substring(0,4): yy;

String code = request.getParameter("jc");
String sort = request.getParameter("sort");
code = (code==null||code.length()>4)?"0101":code;

String db_driver="oracle.jdbc.driver.OracleDriver";
String db_uri="jdbc:oracle:thin:@52.2.210.30:1521:ORA8";
String db_user="kpa_user";
String db_pwd="noway";

response.setHeader("Content-Disposition", "attachment; filename=kpamember.xls");
response.setHeader("Content-Description", "JSP Generated Data");


// connection초기화
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;

String query = "select a.MEMBER_NAME, a.LICENSE_NUMBER, a.PHARMACY_NAME, a.PHARMACY_PHONE_NUMBER1 phone, " +
" a.PHARMACY_ZIPCODE, a.PHARMACY_ADDRESS1, a.kpa_id, a.idchange_flag from kpa_member a, kpa_mem_reg b" +
" where a.region_code like ?||'%' and a.license_number = b.LICENSE_NUMBER and to_char(b.REGISTER_DATE,'yyyy') = ? ";

if(sort != null && sort.equals("zip"))
query += " and rownum <= 1500 order by a.pharmacy_zipcode";
else if(sort != null && sort.equals("lcn"))
query += " and rownum <= 1500 order by a.license_number";
else if(sort != null && sort.equals("pharm"))
query += " and rownum <= 1500 order by a.pharmacy_name";
else
query += " and rownum <= 1500 order by a.MEMBER_NAME";

// 페이지별 회원 목록
Class.forName(db_driver).newInstance();
con=java.sql.DriverManager.getConnection(db_uri,db_user,db_pwd);

try {

pstmt = con.prepareStatement(query);

pstmt.setString(1,code);
pstmt.setString(2,yy);

rs = pstmt.executeQuery();

String m1 = "";
String m2 = "";
%>


<%
out.println("");
while (rs.next()) {
m1 = rs.getString(1);
m2 = rs.getString(2);
out.println("");
}

rs.close();

pstmt.close();
con.close();

} catch(Exception e) {
} finally {
if(rs!=null) rs.close();
if(pstmt!=null) pstmt.close();
if(con!=null) con.close();

}
%>
public
"+m1+""+m2+"
0
  • 댓글 0

  • 로그인을 하시면 댓글을 등록할 수 있습니다.