외부평가 대비

  • JSP Java Beans Front
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="EUC-KR">
    <title>Insert title here</title>
    </head>
    <body>
    <h1>제조사명 조회</h1>
    <form action="result.jsp">
    
    <table border="1">
    <tr><td colspan="3">
    <div style="display:flex;justify-content:center;">
    	제품코드(4) 입력
    </div></td>
    </tr>
    <tr>
    <td colspan="1">제품코드</td>
    <td colspan="2">
    	<input type="input" name="code"/>
    </td>
    </tr>
    <tr>
    <td colspan="3">
    <div style="display:flex;justify-content:center;">
    <button>확인</button>
    </div>
    	
    </td>
    </tr>
    </table>
    
    </form>
    
    </body>
    </html>
    Script
    <%@ page language="java" contentType="text/html; charset=EUC-KR"
        pageEncoding="EUC-KR" import="difficult.*"%>
    <%
    	UserInfo user = new UserInfo("한국인","1004","2019-10-31");
    	String code = request.getParameter("code");
    	ProductInfo product = new ProductInfo(code);
    	product.find();
    %>
    <!DOCTYPE html>
    <html>
    <head>
    <style>
    table,td,th{
    	border:2px solid black;border-collapse:collapse;
    }
    </style>
    <meta charset="EUC-KR">
    <title>Insert title here</title>
    </head>
    <body>
    	
    <h1 style="display:flex;justify-content:center;">제품코드 조회 결과</h1>
    
    <div style="display:flex;justify-content:center;border-top:1px solid black; border-bottom: 1px solid black; padding:10px;">
    <table style="border:2px solid black;border-collapse:collapse">
    <tr><td colspan="3">
    <div style="display:flex;justify-content:center;">
    	제조사 조회 결과
    </div></td>
    </tr>
    <tr>
    <td colspan="1">제품코드</td>
    <td colspan="2">
    	<%= product.getCode() %>
    </td>
    </tr>
    <tr>
    <td colspan="1">제조사명</td>
    <td colspan="2">
    	<%= product.getVendor() %>
    </td>
    </tr>
    <tr>
    <td colspan="1">조회일시</td>
    <td colspan="2">
    	<%= product.getDate() %>
    </td>
    </tr>
    </table>
    </div>
    <div style="display:flex;justify-content:center;">
    작성자: <%=user.getName() %> 비번: <%=user.getCode() %> 작성일: <%=user.getDate() %>
    </div>
    </body>
    </html>
    Class 1
    package difficult;
    import java.util.*;
    public class ProductInfo {
    	private String code;
    	private String vendor;
    	private Date date;
    	public String getCode() {
    		return code;
    	}
    	public void setCode(String code) {
    		this.code = code;
    	}
    	public String getVendor() {
    		return vendor;
    	}
    	public void setVendor(String vendor) {
    		this.vendor = vendor;
    	}
    	public Date getDate() {
    		return date;
    	}
    	public void setDate(Date date) {
    		this.date = date;
    	}
    	public ProductInfo(String code) {
    		super();
    		setCode(code);
    		this.vendor = null;
    		this.date = null;
    	}
    	public void find() {
    		HashMap<String,String> map = new HashMap<>();
    		map.put("A100","삼성전자");
    		map.put("A200","LG전자");
    		map.put("A300","하이닉스");
    		
    		vendor = map.get(code);
    		if(vendor == null) {
    			vendor="등록되지 않은 제품입니다!!";
    		}
    		date = new Date();
    	}
    }
    Class 2
    package difficult;
    
    public class UserInfo {
    	private String name;
    	private String code;
    	private String date;
    	public String getName() {
    		return name;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
    	public String getCode() {
    		return code;
    	}
    	public void setCode(String code) {
    		this.code = code;
    	}
    	public String getDate() {
    		return date;
    	}
    	public void setDate(String date) {
    		this.date = date;
    	}
    	
    	public UserInfo(String name, String code, String date) {
    		super();
    		this.name = name;
    		this.code = code;
    		this.date = date;
    	}	
    }
  • JSP+JDBC Create
    <%@ page language="java" contentType="text/html; charset=EUC-KR"
        pageEncoding="EUC-KR" import="java.sql.*"%>
     
     <%
     	Class.forName("oracle.jdbc.driver.OracleDriver");
     	Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","root");
     	//PreparedStatement stmt = conn.prepareStatement("insert into c_customer values(?,?,?,?,?)");
     	Statement stmt = conn.createStatement();
     	ResultSet rs = stmt.executeQuery("select * from c_customer");
    
     %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="EUC-KR">
    <title>Insert title here</title>
    </head>
    <body>
    	<table border="1">
    	<th>아이디</th>
    	<th>이름</th>
    	<th>이메일</th>
    	<th>전화번호</th>
    	<%
    	while(rs.next()){
    	%>
    	<tr>
    		<td>
    			<%= rs.getString(1) %>
    		</td>
    		<td>
    			<%= rs.getString(3) %>
    		</td>
    		<td>
    			<%= rs.getString(4) %>
    		</td>
    		<td>
    			<%= rs.getString(5) %>
    		</td>
    		
    	</tr>
    	<%} %>
    	</table>
    </body>
    </html>
    Read
    <%@ page language="java" contentType="text/html; charset=EUC-KR"
        pageEncoding="EUC-KR" import="java.sql.*"%>
     
     <%
     	Class.forName("oracle.jdbc.driver.OracleDriver");
     	Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","root");
     	PreparedStatement stmt = conn.prepareStatement("insert into c_customer values(?,?,?,?,?)");
     	
     	stmt.setString(1,request.getParameter("c_id"));
     	stmt.setString(2,request.getParameter("c_pw"));
     	stmt.setString(3,request.getParameter("c_name"));
     	stmt.setString(4,request.getParameter("c_email"));
     	stmt.setString(5,request.getParameter("c_phone"));
     	
     	stmt.execute();
     %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="EUC-KR">
    <title>Insert title here</title>
    </head>
    <body>
    	<a href="NewFile.html">등록화면</a>
    </body>
    </html>

좋은 웹페이지 즐겨찾기