본문 바로가기

JAVA/JSP & Servlet

JSP : 우편번호검색 페이지

zipsearch.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>zipsearch</title>

 

<script type="text/javascript">

        function checkfrm() {

               if(document.frm.dong.value == ""){

                       alert("동이름을 입력하세요");

                       return;

               }

              

               document.frm.submit();

        }

</script>

 

</head>

<body>

 

<form name="frm" method="post" action="zipsearch_ok.jsp">

<table border="1">

<tr>

        <td colspan="2"> 이름 검색</td>

        <!-- colspan : 셀을 합칠때 사용  -->

</tr>

 

<tr>

        <td> <input type="text" name="dong" size="20" value="개포1" /> </td>

        <td> <input type="button" value="검색" onclick="checkfrm()" /> </td>

</tr>

 

</table>

</form>

 

</body>

</html>

 

 

 

 

zipsearch_ok.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

   

<%@page import="java.sql.PreparedStatement"%>

<%@page import="java.sql.DriverManager"%>

<%@page import="java.sql.ResultSet"%>

<%@page import="java.sql.Statement"%>

<%@page import="java.sql.Connection"%>

<%@page import="com.sun.xml.internal.ws.api.ha.StickyFeature"%>

 

 

<%

        request.setCharacterEncoding("UTF-8");

       

 <!-- 직접 zipsearch_ok.jsp 페이지로 접근할 경우 뒤로 보냄 -->

        if(request.getParameter("dong") == null){

%>

 

            <script type="text/javascript">

               alert("동이름을 입력해주세요");

               history.back();

        </script>

       

<%     

        } else{

                      

       

               String dong = request.getParameter("dong");

              

               Connection conn =null;

               Statement stmt = null;

               ResultSet rs = null;

              

               Class.forName("oracle.jdbc.driver.OracleDriver");

               conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "hr", "hr");

              

               String query = "select * from zipcode where DONG like '" + dong + "%'";

               stmt = conn.createStatement();

               rs = stmt.executeQuery(query);

        %>

       

       

        <!DOCTYPE html>

        <html>

        <head>

        <meta charset="UTF-8">

        <title>zipsearch_ok</title>

        <style type="text/css">

               td {border: 1px solid black; width: 150px ; text-align: center;}

        </style>

       

        </head>

       

        <body>

        <table>

        <%

               out.println("<tr>");

               out.println("<td><b>일련번호</b></td>");

               out.println("<td><b>우편번호</b></td>");

               out.println("<td><b>.</b></td>");

               out.println("<td><b>.</b></td>");

               out.println("<td><b></b></td>");

               out.println("<td><b></b></td>");

               out.println("<td><b>앞번지</b></td>");

               out.println("<td><b>뒷번지</b></td>");

               out.println("</tr>");

              

              

               while(rs.next()){

                       out.println("<tr>");

                       out.println("<td>" + rs.getString("seq") + "</td>");

                       out.println("<td>" + rs.getString("zipcode") + "</td>");

                       out.println("<td>" + rs.getString("sido") + "</td>");

                       out.println("<td>" + rs.getString("gugun") + "</td>");

                       out.println("<td>" + rs.getString("dong") + "</td>");

                      

                       //null 처리

                       String ri = rs.getString("ri") == null ? "" : rs.getString("ri");

                       String st_bunji = rs.getString("st_bunji") == null ? "" : rs.getString("st_bunji");

                       String ed_bunji = rs.getString("ed_bunji") == null ? "" : rs.getString("ed_bunji");

                      

                       out.println("<td>" + ri + "</td>");

                       out.println("<td>" + st_bunji + "</td>");

                       out.println("<td>" + ed_bunji + "</td>");           

                       out.println("</tr>");

               }

        %>

        <tr>

               <td colspan="8"> <input type="button" value="뒤로가기" onclick="history.back()"/> </td>

        </tr>

       

        </table>

        </body>

        </html>

        <%

               }

        %>

 

 

 

 

 

 


 

검색창 

 

 

 

 


검색결과

 

 

 

 


zipsearch_ok.jsp 주소로 직접 접근하고자 할때