본문 바로가기

JAVA/JSP & Servlet

JSP : 우편번호검색 페이지2 -한 페이지에서 입력 & 검색-

 

<%@ 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");

       

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

%>

        <!DOCTYPE html>

        <html>

        <head>

        <meta charset="UTF-8">

        <title>zipsearch_02</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_02.jsp">

               <table border="1">

               <tr>

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

 

               </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>

       

<%     

        } 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);

        %>

       

       

        <html>

        <head>

        <meta charset="UTF-8">

        <title>zipsearch_02</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>

        <%

               }

        %>

 

 

 

 

 

 

 


 

입력화면 

 

 

 


검색결과