'우편번호찾기'에 해당되는 글 1건

  1. 2009.01.20 [JAVA] 우편번호 찾기 - JSP

-_- 우편번호...떡밥인가효?

DB에 우편번호테이블을 먼저 생성해야 한다. 디비는 오라클을 사용했다.

1. 찾기 첫페이지

<?xml version="1.0" encoding="EUC-KR" ?>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR" />
<title>Address</title>
<link  href="style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="zipfind.js"></script>
</head>

<body>
<div>
Find Address<br/>
<form name="ad" method="get" action="dataHandle.jsp" onsubmit="return searchDb()">
<input type="text" name="address" id="dong" class="txtbox"/>
<input type="submit" value="find" class="bt" />
</form>
</div>
</body>
</html>

2. 디비 검색 결과 페이지

<?xml version="1.0" encoding="EUC-KR" ?>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page import="java.sql.Connection"%>
<
%@page import="java.sql.PreparedStatement"%>
<
%@page import="java.sql.ResultSet"%>
<
%@page import="java.sql.DriverManager"%>
<
%@page import="java.sql.SQLException"%>
<
%@page import="zip.data.DTO.ZipVO"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR" />
<title>Address</title>
<link  href="style2.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="zipfind.js"></script>
</head>
<body>

<div id="result">
<form action="myAddress.jsp" method="post">
<table border="0" cellpadding="0"cellspacing="0" >
<tr  class="title">
<td>우편번호</td>
<td>시, 도</td>
<td>구, 군</td>
<td>동</td>
<td>번지</td>
<td>선택</td>
</tr>
<tr class="line">
<td colspan="5"></td>
</tr>
<%
request.setCharacterEncoding("euc-kr");
String address = request.getParameter("address");
//sql에서 읽을 수 있게 넘어오는 값을 타입 변형
address = new String(address.getBytes("8859_1"),"euc-kr");

//1.드라이버 로딩
  try{
   Class.forName("oracle.jdbc.OracleDriver");
  }catch(ClassNotFoundException e){
   System.err.print("ClassNotFoundException");
  }

Connection con=null;
PreparedStatement pstmt = null;
ResultSet rs = null;

try{
 String zipcode, sido, gugun, dong, bunji;
 String dburl="jdbc:oracle:thin:@localhost:1521:ORCL";
 String dbUser = "scott";
 String dbPass = "tiger";
 
 StringBuffer query = new StringBuffer();
 query.append("select zipcode, sido, gugun, dong, bunji from zipcode where dong like '%");
 query.append(address);
 query.append("%'");

//2.데이터베이스 커넥션 생성
 con = DriverManager.getConnection(dburl,dbUser,dbPass);
 
//3.statement 생성
 pstmt = con.prepareStatement(query.toString());

//4.쿼리 실행
 rs = pstmt.executeQuery();

//5.쿼리 실행 결과 출력
 while(rs.next()){
 
%>
<tr class="line">
<td colspan="5"></td>
</tr>
<tr class="value">

<td><%= rs.getString("zipcode") %></td>
<td><%= rs.getString("sido") %></td>
<td><%= rs.getString("gugun") %></td>
<td><%= rs.getString("dong") %></td>
<td><%= rs.getString("bunji") %></td>
<td>
<input type="button" value="선택" class="bt"
onclick="btnSelectClick('<%= rs.getString("zipcode") %>', '<%= rs.getString("sido") %>','<%= rs.getString("gugun") %>','<%= rs.getString("dong") %>','<%= rs.getString("bunji") %>')"/>
</td>
</tr>
<tr class="line">
<td colspan="5"></td>
</tr>

<%
}

}catch(SQLException e){

 e.printStackTrace();
}finally{
//6.사용한 statement 종료
 if(rs!=null){
  rs.close();
 }
 if(pstmt!=null){
  pstmt.close();
 }
//7.커넥션 종료
 if(con!=null){
  try{
   con.close();
 }catch(SQLException e){
 
  e.printStackTrace();
 }
  
 }
}

%>
<input type="hidden" name="zipcode"  id="zipcode"/>
<input type="hidden" name="sido" id="sido"/>
<input type="hidden" name="gugun" id="gugun"/>
<input type="hidden" name="dong" id="dong"/>
<input type="hidden" name="bunji" id="bunji"/>

</table>
</form>
</div>
</body>
</html> 

3. 상세 주소로 이동

<%@ page contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR" %>
<% request.setCharacterEncoding("euc-kr"); %>

<jsp:useBean id="myaddress" class="zip.data.DTO.ZipVO"></jsp:useBean>
<jsp:setProperty name="myaddress" property="*"/>
<html>
<head>
<style type="text/css">
body {margin: 0;padding: 0;height: 100%;width: 100%;}
div {font-size: 12px;font-family: 돋움;}

#table {position: absolute;top: 30%;left: 25%;height:80px;width:400px;border: 2px solid #0046AD;}
#txtaddress {position: absolute;top: 1%;left: 5%;padding: 3px}
#btarea {position: absolute;top:65%;left: 5%;padding: 3px;}

.txtarea {font:normal 14px Dotum,"돋움"; }
.txtbunji {font-size: 12px;width: 354px;}
.bt{float:right; border:1px solid #0046AD;font:normal 12px Dotum,"돋움";color:#444444;width:60px;}
</style>
<title>Insert title here</title>
</head>
<body>

<div id="table">
<form action="">

<div id="txtaddress">
<textarea rows="1" cols="50" style="overflow: hidden;" readonly="readonly" class="txtarea" >
<jsp:getProperty name="myaddress" property="zipcode"/> <jsp:getProperty name="myaddress" property="sido"/>시 <jsp:getProperty name="myaddress" property="gugun"/> <jsp:getProperty name="myaddress" property="dong"/>
</textarea>
<br/>
<input type="text" name="juso" id="realbunji" class="txtbunji"/>
</div>

<div id="btarea">
<input type="submit" name="confirm" id="confirmbt" value="확인" class="bt"/>
</div>

</form>
</div>

</body>
</html>


Posted by zeide
,