java 60

JSP - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(10) ๋กœ๊ทธ์ธ -v2(Cookie,ELํ‘œํ˜„์‹, JSTL ์ ์šฉ)

1. ELํ‘œํ˜„์‹ https://www.javatpoint.com/EL-expression-in-jsp JSP Expression Language | EL - javatpoint JSP Expression Language or EL with examples of session tracking, implicit objects, el, jstl, mvc, custom tags, file upload, file download, interview questions etc. www.javatpoint.com 2. JSP Scope๋ž€? pageScope > requestScope > sessionScope > applicationScope ํ‚ค ๊ฐ’์ด ์ค‘๋ณต๋˜๋ฉด ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด scope์˜ value๋ฅผ returnํ•œ๋‹ค. t..

java 2020.11.09

JSP - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(8) ํšŒ์›๊ฐ€์ž…

1. ์ฃผ์˜ํ•  ์  (1) ๋ชจ๋“  ์‘๋‹ต์€ requestDispather๋กœ ํ•œ๋‹ค. ์ด์œ ๋Š” ์ฃผ์†Œ๋ฅผ ๋‚จ๊ธฐ์ง€ ์•Š๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ ๋“ค๊ณ  ์ด๋™ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ (2) ์‹คํŒจ์‹œ์—๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ์‘๋‹ตํ•œ๋‹ค.history.back() (3) DB์˜ User table์˜ username ์ œ์•ฝ์กฐ๊ฑด์— uniq ๊ฑธ์–ด์•ผํ•จ alter table user add unique(username); 2. include/nav.jsp seoha Post join login 3. include/footer.jsp made in seoha:-) 4. index/.jsp 5. dao/USerDao.java package com.cos.board.dao; import java.sql.Connection; import java.sql.PreparedStatem..

java 2020.11.09

JAVA - Thread์ดํ•ดํ•˜๊ธฐ

package com.cos.board.test; // JavaScript๋Š” Function์ด 1๊ธ‰ ๊ฐ์ฒด, ๋ณ€์ˆ˜๋ฅผ ์–ด๋””์„œ๋‚˜ ์„ ์–ธํ•  ์ˆ˜ ์žˆ๋‹ค. // Java์˜ 1๊ธ‰ ๊ฐ์ฒด๋Š”class๊ฐ€ ์œ ์ผ, ํ•จ์ˆ˜๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋„˜๊ธธ ์ˆ˜ ์—†๋‹ค. interface SendEventListener { // 1. return ๋ฐ›๊ณ  ์‹ถ์€ ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ž…๋ ฅ. public abstract void callback(int money); } class ํ™˜์ „์†Œ { private int money = 10; public void send(SendEventListener sendEventListener) { // 2. ํ•จ์ˆ˜๋ฅผ void๋กœ ๋ณ€๊ฒฝ , ์Šค๋ ˆ๋“œ๋ฅผ ์“ฐ๋Š” ์ˆœ๊ฐ„ ๋ฆฌํ„ดํ˜•์€ ์—†๋‹ค. callback, ์ข…๋ฃŒ๋ฅผ ์•Œ๋ ค์คŒ. // 3. ํ•ด๋‹น ํ•จ์ˆ˜..

java 2020.11.09

JSP - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(7) ์˜ค๋ฅ˜๋ฌธ์ •๋ฆฌ:-)

์‹ค์งˆ์ ์œผ๋กœ ์ฟผ๋ฆฌ๋ฌธ์„ ๋‚ ๋ฆฌ๋Š” UserDaoTestํŒŒ์ผ์—์„œ ๋‚˜ํƒ€๋‚˜๋Š” ์˜ค๋ฅ˜๋“ค ํ™•์ธํ•˜๊ธฐ 1. save()ํ•จ์ˆ˜์—์„œ ? ์ œ๊ฑฐ ํ›„ ์‹คํ–‰ํ•ด๋ณด๊ธฐ -> java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2). ->(๋ฒˆ์—ญ) java.sql.SQLException : ๋งค๊ฐœ ๋ณ€์ˆ˜ ์ƒ‰์ธ์ด ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚ฌ์Šต๋‹ˆ๋‹ค (3> ๋งค๊ฐœ ๋ณ€์ˆ˜ ์ˆ˜, 2). : ?์˜ ๊ฐฏ์ˆ˜๋งŒํผpstmt.setString(1, "love"); setํ˜•์‹(์ธ๋ฑ์Šค,"๊ฐ’") ํ•ด์ฃผ์–ด์•ผํ•˜๋Š”๋ฐ ๋ฒ”์œ„๊ฐ€ ์•ˆ๋งž์Œ. 2. save()ํ•จ์ˆ˜์—์„œ setString(์—†๋Š”์ธ๋ฑ์Šค, ๊ฐ’) ์ธ๋ฑ์Šค ๋ฒˆํ˜ธ ๋งˆ์Œ๋Œ€๋กœ ๋„ฃ์–ด๋ณด๊ณ  ์‹คํ–‰ํ•ด๋ณด๊ธฐ ->java.sql.SQLException: Parameter i..

java 2020.11.09

JSP - ๊ฒŒ์‹œํŒ ๋งŒ๋“ค๊ธฐ(6) PrepareStatement๋ฅผ ์ด์šฉํ•œ CRUD ํ…Œ์ŠคํŠธ

1.CRUD (1) C -> Create -> insert -> HTTP(POST) (2) R -> Read -> select -> HTTP(GET) (3) U -> Update - > update -> HTTP(PUT) (4) D -> Delete -> delete -> HTTP(DELETE) 2.User CRUD ํ…Œ์ŠคํŠธ (1) model/User.java package com.cos.board.model; import java.sql.Timestamp; // model, vo(value object), bean(์ฝฉ) public class User { private int id; private String username; private String password; private String ema..

java 2020.11.09

JSP - ๊ฒŒ์‹œํŒ ๋งŒ๋“ค๊ธฐ(5) DB Connection Pool(CP)

p.443 DB Connection Pool(CP) : datasource 1. ํ†ฐ์บฃ ์‚ฌ์ดํŠธ๋กœ ์ด๋™ (http://tomcat.apache.org/) 2. ๋ฒ„์ „์— ๋งž๊ฒŒ ํด๋ฆญ ํ†ฐ์บฃ ํŽ˜์ด์ง€ ์™ผ์ชฝ ๋ฐ” 3. JDBC Datasouce๋กœ ์ด๋™ 4. MySQL DBCP ์˜ˆ์ œ ๋ณด๊ธฐ 5. JDBC MySQL Connector ๋‹ค์šด๋กœ๋“œ https://www.mysql.com/products/connector/๋กœ ์ด๋™ 6. MySQL๋ฒ„์ „์œผ๋กœ ๋‹ค์šด๋กœ๋“œ, ์••์ถ• ํ’€๊ณ  jarํŒŒ์ผ lib์— ๋„ฃ๊ธฐ, ๋”ฐ๋กœ ๋นŒ๋“œํŒจ์Šค ์•ˆํ•ด๋„๋จ 7. ์†Œ์Šค์ฝ”๋“œ ์ž‘์„ฑ http://tomcat.apache.org/tomcat-8.5-doc/jndi-datasource-examples-howto.html#MySQL_DBCP_2_Example http://tomc..

java 2020.11.09

JSP - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(2) - MySQL ํ•œ๊ธ€ ์…‹ํŒ…ํ•˜๊ธฐ, ์œ ์ € ์ƒ์„ฑ

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์„œ๋ฒ„๋ฅผ urf-8๋กœ ๋ณ€๊ฒฝํ•ด์•ผํ•œ๋‹ค. ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์œˆ๋„์šฐ์™€ ๋ฆฌ๋ˆ…์Šค๊ฐ€ ๋‹ค๋ฅด๋‹ค. ๊ฒฝ๋กœ : C:\ProgramData\MySQL\MySQL Server 5.7 1. ์œˆ๋„์šฐ (1) my.ini ํŒŒ์ผ ์ฐพ๊ธฐ ๊ฒฝ๋กœ : C:\ProgramData\MySQL\MySQL Server 5.7 (2) ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์œผ๋กœ my.iniํŒŒ์ผ ์—ด์–ด์„œ ์ˆ˜์ •ํ•˜๊ธฐ ๋ฉ”๋ชจ์žฅ ๋งˆ์šฐ์Šค์šฐํด๋ฆญํ•˜์—ฌ ๊ด€๋ฆฌ์ž๊ถŒํ•œ์œผ๋กœ ์—ด๊ธฐ, ๋ชจ๋“ ํŒŒ์ผ๋กœ my.ini์—ด๊ธฐ [client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] collation-server = utf8_unicode_ci init-connect='SET NAMES utf8' init_connect='SET col..

java 2020.11.09

JSP - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(1) - ํŒฉํ† ๋ฆฌ ํŒจํ„ด ์˜ˆ์ œ

์ฐธ๊ณ ์ž๋ฃŒ : https://readystory.tistory.com/117 [์ƒ์„ฑ ํŒจํ„ด] ํŒฉํ† ๋ฆฌ ํŒจํ„ด(Factory Pattern) ์ดํ•ด ๋ฐ ์˜ˆ์ œ ์ด๋ฒˆ์— ์‚ดํŽด๋ณผ ๋””์ž์ธ ํŒจํ„ด์€ ๊ฐ€์žฅ ์œ ๋ช…ํ•œ ๋””์ž์ธ ํŒจํ„ด ์ค‘ ํ•˜๋‚˜์ธ ํŒฉํ† ๋ฆฌ ํŒจํ„ด(Factory Pattern)์ž…๋‹ˆ๋‹ค. ์ด ํŒฉํ† ๋ฆฌ ํŒจํ„ด์€ ์กฐ๊ธˆ ๋” ๊ตฌ์ฒด์ ์ธ ์šฉ์–ด์ธ ํŒฉํ† ๋ฆฌ ๋ฉ”์†Œ๋“œ ํŒจํ„ด(Factory Method Pattern)์œผ๋กœ๋„ ๋„๋ฆฌ readystory.tistory.com [์ƒ์„ฑ ํŒจํ„ด] ํŒฉํ† ๋ฆฌ ํŒจํ„ด(Factory Pattern) ์ดํ•ด ๋ฐ ์˜ˆ์ œ ์ด๋ฒˆ์— ์‚ดํŽด๋ณผ ๋””์ž์ธ ํŒจํ„ด์€ ๊ฐ€์žฅ ์œ ๋ช…ํ•œ ๋””์ž์ธ ํŒจํ„ด ์ค‘ ํ•˜๋‚˜์ธ ํŒฉํ† ๋ฆฌ ํŒจํ„ด(Factory Pattern)์ž…๋‹ˆ๋‹ค. ์ด ํŒฉํ† ๋ฆฌ ํŒจํ„ด์€ ์กฐ๊ธˆ ๋” ๊ตฌ์ฒด์ ์ธ ์šฉ์–ด์ธ ํŒฉํ† ๋ฆฌ ๋ฉ”์†Œ๋“œ ํŒจํ„ด(Factory Method Pattern)์œผ๋กœ..

java 2020.11.09

MVCํŒจํ„ด

* ๊ธฐ์กด์˜ ๋ฐฉ์‹ ๋‹จ์  - MVC๋ง๊ณ ๋„ MVP, MCCM, ObserverํŒจํ„ด ๋“ฑ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. - MVC์ด ๊ธฐ๋ณธ์ด๊ธฐ๋•Œ๋ฌธ์— ๊ฐ€์žฅ ๋งŽ์ด ๋ฐฐ์›€. ๋‹จ์  ๋ณด์™„ ๋ฐฉ๋ฒ• - JSP๋ฐฉ์‹ JSP์—์„œ JSP๋กœ ์ด๋™ํ•œ๋‹ค. URL๋ฐฉ์‹์œผ๋กœ ํŒŒ์ผ๋ช…์„์ฐพ์Œ. ์„œ๋ธ”๋ฆฟ(์–ด๋…ธํ…Œ์ด์…˜) ์‚ฌ์šฉ - ๋น„์ง€๋‹ˆ์Šค๋กœ์ง + ๋ทฐ๋กœ์ง -> ๊ด€์‹ฌ์‚ฌ๊ฐ€ ๋ถ„๋ฆฌ๊ฐ€ ์•ˆ๋˜์–ด ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง„๋‹ค. MVCํŒจํ„ด ์‚ฌ์šฉ - ํŒจํ„ด์ด ์—†๋‹ค. ๊ฐœ๋ฐœ์ž ๊ฐ๊ฐ ์ง€์ผœ์•ผํ•  ๊ทœ์น™์ด ์—†๋‹ค -> ์ธํ„ฐํŽ˜์ด์Šค ์‚ฌ์šฉ ํŒฉํ† ๋ฆฌ ์‚ฌ์šฉ ๋ณด์™„ ๋ฐฉ๋ฒ• - JSP๋ฐฉ์‹ JSP์—์„œ JSP๋กœ ์ด๋™ํ•œ๋‹ค. URL๋ฐฉ์‹์œผ๋กœ ํŒŒ์ผ๋ช…์„์ฐพ์Œ. ์„œ๋ธ”๋ฆฟ(์–ด๋…ธํ…Œ์ด์…˜) ์‚ฌ์šฉ - ๋น„์ง€๋‹ˆ์Šค๋กœ์ง + ๋ทฐ๋กœ์ง -> ๊ด€์‹ฌ์‚ฌ๊ฐ€ ๋ถ„๋ฆฌ๊ฐ€ ์•ˆ๋˜์–ด ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง„๋‹ค. MVCํŒจํ„ด ์‚ฌ์šฉ - ํŒจํ„ด์ด ์—†๋‹ค. ๊ฐœ๋ฐœ์ž ๊ฐ๊ฐ ์ง€์ผœ์•ผํ•  ๊ทœ์น™์ด ์—†๋‹ค -> ์ธํ„ฐํŽ˜์ด์Šค ์‚ฌ์šฉ ํŒฉํ† ..

java 2020.11.09

JAVA - Exception ์ข…๋ฅ˜

ClassNotFoundException ํด๋ž˜์Šค๋ฅผ ์ฐพ์ง€ ๋ชปํ•จ CloneNotSupportedException Cloneable ์ธํ„ฐํŽ˜์ด์Šค ๋ฏธ๊ตฌํ˜„ IllegalAccessException ํด๋ž˜์Šค ์ ‘๊ทผ์„ ๋ชปํ•จ InstantiationException ์ถ”์ƒ ํด๋ž˜์Šค ๋˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ธ์Šคํ„ด์Šคํ™” ํ•˜๊ณ ์ž ํ• ๋•Œ InterruptedException ์“ฐ๋ ˆ๋“œ๊ฐ€ ์ค‘๋‹จ ๋˜์—ˆ์„๋•Œ NoSuchFieldException ์ง€์ •๋œ ํ•„๋“œ๊ฐ€ ์—†์„๋•Œ NoSuchMethodException ์ง€์ •๋œ ๋ฉ”์†Œ๋“œ๊ฐ€ ์—†์„๋•Œ [IOException] CharConversionException ๋ฌธ์ž ๋ณ€ํ™˜์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„๋•Œ [IOException] EOFException ํŒŒ์ผ์˜ ๋์— ๋„๋‹ฌํ–ˆ์„๋•Œ [IOException] FileNotFoundExcept..

java 2020.11.09