20220310 복습
List < > list = new ArrayList < > ( ); + LegoData를 사용하여 처리!
데이터가 넘어오면 LegoData , 후 list.add( );
1. 데이터가 넘어온다.
2. LegoData 객체 list.add( );
3. 확인 (목록)
java : Scanner 로 입력
jsp : 폼컨트롤( input type = "text" name = "" )를 사용해서 입력.
ld ( LegoData ) 에는 application을 걸면 덮어씌움.
객체가 존재하면 가져오고, 객체가 없으면 새로 생성.
lm ( LegoManager ) 에만 scope를 걸자.
변수 목록
private String modelNum
private String modelName
private String year
private String maker
private String price
private String manual
private String age
lms.html
< !DOCTYPE html >
< html >
< head >
< meta charset="UTF-8" >
< title>레고관리시스템< /title >
< /head >
< body >
< form method="post" action="lms.jsp" >
< table width=100% border=1 >
< tr >
< td>모델번호< /td >
< td>< input type="text" name="modelNum" >< /td >
< /tr >
< tr >
< td >모델명< /td >
< td >< input type="text" name="modelName" >< /td >
< /tr >
< tr >
< td >연도< /td >
< td >
< select name="year" >
<option value="2022" selected>2022
<option value="2021">2021
<option value="2020">2020
<option value="2019">2019
<option value="2018">2018
< /select >
< /td >
< /tr >
< tr >
< td >제조사< /td >
< td >< input type="text" name="maker" >< /td >
< /tr >
< tr >
< td >가격< /td >
< td >< input type="text" name="price" >< /td >
< /tr >
< tr >
< td >설명서< /td >
< td >
< input type="radio" name="manual" value="Y" >Y
< input type="radio" name="manual" value="N" >N
< /td >
< /tr >
< tr >
< td >연령< /td >
< td >< input type="text" name="age" >< /td >
< /tr >
< tr >
< td >< input type="submit" value="레고등록" >< /td >
< td >< /td >
< /tr >
< /table >
< /form >
< /body >
< /html >
lms.jsp
< %@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="UTF-8"% >
< % request.setCharacterEncoding("UTF-8"); % >
< jsp:useBean id="ld" class="lms.LegoData" /> ----- scope 걸면 덮어씌우기 되어버리니 주의!
< jsp:setProperty property="*" name="ld" />
< jsp:useBean id="lm" class="lms.LegoManager" scope="application" />
< !DOCTYPE html >
< html >
< head >
< meta charset="UTF-8" >
< title>레고관리시스템< /title >
< /head >
< body >
< %
out.println(ld.getModelNum());
out.println(ld.getModelName());
out.println(ld.getYear());
out.println(ld.getMaker());
out.println(ld.getPrice());
out.println(ld.getManual());
out.println(ld.getAge());
lm.insert(ld);
% >
< /body >
< /html >
lms_list.jsp
< %@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
< %@ page import="lms.LegoManager" %>
< %@ page import="lms.LegoData" %>
< %@ page import="java.util.Date" %>
< %@ page import="java.text.SimpleDateFormat" %>
< %
Date nowTime = new Date();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
% >
< jsp:useBean id="lm" class="lms.LegoManager" scope="application" />
< !DOCTYPE html >
< html >
< head >
< meta charset="UTF-8" >
< title>Insert title here< /title >
< /head >
< body >
< table width=100% border=1 >
< tr >
< td >모델번호< /td >
< td >모델명< /td >
< td >연도< /td >
< td >제조사< /td >
< td >가격< /td >
< td >연령< /td >
< td >설명서< /td >
< td >날짜< /td >
< /tr >
< tr >
< td colspan=8 >
< /td >
< /tr >
< % for( LegoData ld : lm.getAllList()) { %>
< tr >
< td >< %=ld.getModelNum() %>< /td >
< td >< %=ld.getModelName() %>< /td >
< td >< %=ld.getYear() %>< /td >
< td >< %=ld.getMaker() %>< /td >
< td >< %=ld.getPrice() %>< /td >
< td >< %=ld.getManual() %>< /td >
< td >< %=ld.getAge() %>< /td >
< td >< %=nowTime %>< /td >
< /tr >
< % } % >
< tr >
< td colspan=8 >
[1][2][3][4][5][6][7][8][9][10] < br >
< /td >
< /tr >
< /table >
< /body >
< /html >
LegoManager.java
package lms;
import java.util.ArrayList;
import java.util.List;
public class LegoManager {
List< LegoData > list = new ArrayList< LegoData >( );
public void insert(LegoData ld) {
list.add(ld);
}
public List< LegoData > getAllList() { ----- List < LegoData > 의 자료형태로 list배열을 return !
return list;
}
}
LegoData.java
package lms;
public class LegoData {
private String modelNum;
private String modelName;
private String year;
private String maker;
private String price;
private String age;
private String manual;
public String getModelNum() {
return modelNum;
}
public void setModelNum(String modelNum) {
this.modelNum = modelNum;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getMaker() {
return maker;
}
public void setMaker(String maker) {
this.maker = maker;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getManual() {
return manual;
}
public void setManual(String manual) {
this.manual = manual;
}
}