예외는 두 가지 종류 :

일반 예외, exception 그리고 실행 예외 runtime exception

 

예외 처리 코드란 : 프로그램에서 예외가 발생 하였을 때 갑작스러운 종료를 막기위해 처리하는 코드.

 

NullPointerException = 객체 참조가 없을때!

ArrayIndexOutOfBoundsException = 배열에서 인덱스 범위를 초과했을때

NumberFormatException = 문자열인데 숫자로 변경했을때

ClassCastException = 안맞는 타입 변환(casting)을 했을 경우. Instanceof 활용 ok

 

모든 예외 객체는 exception를 상속하기 때문에 exception에 있는 getMessage 그리고 printStackTrace를 많이 사용한다

getMessage는 오류 메시지를 얻고,

printStackTrace는 오류의 경로를 추적할 때 사용한다

 

throw는 강제로 예외를 발생하는 것

throws는 예외의 책임을 다른데에 전달하는 것

 

java.lang안에 있는 클래스는 import할 필요가 없다

object는 자바의 최상위 부모 클래스

 

object equals의 원리는 모든 객체는 object를 상속받아서 비교할 때 자동으로 object타입으로 형변환이된다.

 

객체 해시코드란 객체를 식별할 하나의 정수값을 말한다.

 

System은 다 정적으로 이루어져있다

 

String은 내부 문자열을 수정할 수 없다, 그래서 수정을 할 때 마다 새로운 객체를 생성하는것이며, 메모리에 과부화, 즉 성능 저하가 될 요인이 될 수 있다.

그래서 stringbuilder 그리고 stringbuffer를 사용하는 것이 바람직하다.

Stringbuilder stringbuffer의 큰 차이점은 stringbuffer multi-thread 환경에서 사용할 수 있도록 동기화가 되었있다.

 

Calendar은 추상 클래스여서 정적인 getInstance를 통해 생성이가능하다. 그 이유는 각 지역마다 사용하는 시간법이 달라서, 만약 한국인데 la시간을 사용하고 싶다면 TimeZone를 사용하며 된다. TimeZone.getAvailableIDs();를 사용하면 가능한 timezone들이 보인다.

 

MessageFormat.format(문자열, 해당 value);

'ETC' 카테고리의 다른 글

이것이 자바다 노트3(제너릭)  (1) 2019.12.14
이것이 자바다 노트2(스레드 + 멀티스레드)  (0) 2019.12.14
Garbage Collector  (0) 2019.12.01
Comparable vs Comparator  (0) 2019.12.01
Algorithm time complexity  (2) 2019.12.01

Java.lang.OutOfMemoryError ==not able to use heap because heap is full, NEED TO CHECK FOR MEMORY LEAKS!!!

 

Garbage collection has 3 steps:

 

Mark- starts from root node of your application, walks object graph and marks objects that are reachable as live

Sweep/delete – delete unreachable objects, sweeps from heap

Compacting- Arranging everything in order, when unreachable objects are sweeped, there are holes empty places so then compacting comes in and arranges objects in order.

 

Heap is divided into two spaces, young generation and old(tenured) generation :

 

Eden space – a place where new objects are created, references to a book of genesis

When eden space is full, that is when minor(small) garbage collector kicks in removes unreachable objects and moves them to survivor space

Survivor space - Having two survivor space prevents compacting step to be used again.

Old generation – a place in heap where long survived objects are stored

Major garabage collector kicks when old generation is almost full, marks, sweep and compacts new and old generation. Application comes to a halt while this is happening.

 

-XX:MaxTenuringThreshold  = how many times object need to survive to be placed into old generation

 

 

*Performance*

responsiveness/latency- how quickly an application response with a requested piece of data

ex. If a ui on a web application focuses on responsiveness, large pause times are not acceptable.

 

Throughput = throughput focuses on maximizing the amount of work by an application in a specific period of time.

Ex. The number of jobs that a batch of program can complete in an hour

The number of database queries that can be completed in an hour

*Type of garbage collectors*

 

A serial garbage collector – basic garbage collector that runs in a single thread, can be used for basic applications

Pause, runs, pause, runs

 

A concurrent collector – a thread that performs gc along with application execution as the application runs, does not wait for the old generation to be full – stop the world only during mark/re-mark

 

A parallel collector - Uses multiple cpus to perform gc. Multiple threads doing mark/sweep etc. does not kick in until heap is full or near full.

 

Use concurrent collector when(responsiveness/latency)

There is more memory

There is high number of cpus to spare

Application demands short pauses

 

Use a parallel collector when(throughput!)

Application demands high throughput and can withstand pauses

 

Most application use concurrent garbage collector because of high responsiveness! Of course!

 

As of Java 1.7, g1 was introduced

G1 divides heap into small regions. When a certain region has a lot of unreachable objects, gc kicks in. g1 does not care for young or old or eden survivor space.

-      Parallelism and concurrency together

-      Low pauses with fragmentation

-      Better heap utilization

Uptil 1.6, parallelgc was default

1.7 + g1gc is the default

 

Xmsvalue = setting the minimum value to heap

Xmxvalue = maxium value to heap(default 256)

Xx:newratio=ratio (2means 1/3 Y + 2/3 O(T))

Xx:newsize=size   how much amount of memory set aside for eden space

Xx:permsize    a size assigned to meta-data(static class data etc)

Xx:maxpermsize     def 64m          

 

 

게임회사에서 면접을 보면서 대답을 못 한 질문이 많았지만 개발자로서 꼭 알아야 하는 이론인데 공부를 하지 않아서 답변 못 했던 질문이 2개였는데 하나가

1. 가비지 컬렉터가 어떻게 돌아가는지

2. Big O에 대해서 



전에 자바 메모리 구조 포스트에 올렸듯이 meta-data에는 static 그리고 클래스 자료들이 저장되고, stack 안에서는 local variable들이 저장되면서 객체의 변수도 같이 저장되는데 heap 영역에서 객체의 자료가 저장된다. stack에서는 heap의 참고 주소만 가지고 있어서 만약 heap에서 자료를 참고하지 않으면 가비지 컬렌터가 돌아간다는 까지 알고 있었는데, 힙 영역 안에서 어떻게 작동하는 원리를 물어보셔서 많이 당황한 기억이 난다.



그래서 집에 와서 공부한 게 빅오랑 가비지 컬렉터다.



영어로 배워서 영어로 위에 설명을 적었는데 나중에 면접 가서 설명은 한국말로 해야 해서 간략하게 정리해보겠습니다



가비지 컬렉터는 3가지 단계로 작동을 한다

mark, sweep, compact

힙안에는 new generation 그리고 old generation이 존재한다

new generation 안에는 eden 그리고 2개의 survivor 영역

old generation은 그냥 old generation

가비지 컬렉터는 new generation에 eden이 다 찾을 때 minor garbage collector가 작동하면서 참조 안 되는 객체는 지우면서 참조되는 자료는 survivor 영역으로

만약 오래 존재하는 자료면 old generation으로 이동

old generation 메모리 영역이 거의 다  찼을 때 major gc 발동. major gc는 new와 old다 mark sweep compact 함

이런 식으로 메모리가 정리된다



가비지 컬렉터의 종류는 현재 4가지

원래는 parallel gc 를 default로 사용했지만 1.7 이후부터 g1 gc 사용

g1서부터는 old new generation 구분 없이 영역을 나누어서 해당 영역이 차면 gc 발동, g1이 parallel 그리고 concurrent와 같이 사용하는 느낌



다음 면접 때 물어보면 확실히 설명할 수 있을 것 같다

source : https://www.youtube.com/watch?v=UnaNQgzw4zY&t=198s

'ETC' 카테고리의 다른 글

이것이 자바다 노트2(스레드 + 멀티스레드)  (0) 2019.12.14
이것이 자바다 노트1  (0) 2019.12.09
Comparable vs Comparator  (0) 2019.12.01
Algorithm time complexity  (2) 2019.12.01
자바 메모리 구조  (0) 2019.11.23

Comparable is a interface you need to implement to a Object where a specific compare standard has to be defined by overriding compareTo method.

compareTo needs to be returned as an int value, + for moving up a list, - for moving down, 0 for staying at the same place.

Wrapper type data does NOT need comparable interface to be compared since all Wrapper class already has been implemented with a Comparable interface. String, char are compared by unicode, numbers are obviously compared by numbers. You could implement Comparable on an object class if standard comparing method does not suit your needs. 

Comparator on the other hand is another interface used with purpose of for Collections.sort or Arrays.sort to directly assign comparable standards. anonymous class(?) is assigned on the back of collections.sort or arrays.sort and overrides compare method. the compare method is also an int return method and is same as compareTo method but the difference is number of parameter. compare requires two while compareTo only requires one. This is very simple to understand because you implement comparable to a object class, comparing class variable to parameter while for comparator you do not have a class object to compare to so you need two parameter to be compared. 

Collections.sort performs merge sort algorithm

 

 

'ETC' 카테고리의 다른 글

이것이 자바다 노트1  (0) 2019.12.09
Garbage Collector  (0) 2019.12.01
Algorithm time complexity  (2) 2019.12.01
자바 메모리 구조  (0) 2019.11.23
various query  (0) 2019.11.14

There are three things to consider when choosing which code to use

1. Time complexity(Big o)

2. Space complexity(How much memory it would consume)

3. Code readability

 

면접날 빅오 대해서 질문을 받았는데 답변을 못해서 집에서 찾아보니 코드를 선택할 때 세가지 요소가 있다는걸 발견했다.

간단하게 첫번째인 빅오에대해서 설명을 적어보도록 하겠습니다

 

입출력 상관없이 똑같은 속도를 유지하는 것은 O(1), 파라미터, 값에 변화에 영향을 받지 않고 똑같은 속도(constant complexity)
O(n)는 증가하는 값에 따라 같이 변화하는 것, linear complexity ex. for loop
O(n^2)는 제일 오래 걸리는 속도, quadratic complexity ex·이중 포문


O(1) = 주방장이 손님 수 상관없이 대량으로 조리해주는 속도  

O(log n) = 주방장이 주문들어온 음식들을 한번에 같이 조리해서 주는 속도
O(n) = 주방장이 손님마다 하나의 음식을 조리해서 주는 속도
O(n^2) = 주방장이 각 손님이 한에 모든 요리를 하나씩 다 조리해 주는 속도

 

 

'ETC' 카테고리의 다른 글

Garbage Collector  (0) 2019.12.01
Comparable vs Comparator  (0) 2019.12.01
자바 메모리 구조  (0) 2019.11.23
various query  (0) 2019.11.14
Various html  (0) 2019.11.14

이넘, 상수, 메소드들은 메소드영역에 존재

객체는 heap, 참조안되면 garbage collector와서 지움

stack은 객체의 변수, 기본 변수

'ETC' 카테고리의 다른 글

Comparable vs Comparator  (0) 2019.12.01
Algorithm time complexity  (2) 2019.12.01
various query  (0) 2019.11.14
Various html  (0) 2019.11.14
Settings  (0) 2019.11.14

1. board

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CREATE TABLE `board` (
  `boardId` int(11NOT NULL AUTO_INCREMENT,
  `bUsername` varchar(10DEFAULT NULL,
  `bTitle` varchar(20DEFAULT NULL,
  `bContent` varchar(200DEFAULT NULL,
  `bDate` timestamp NULL DEFAULT NULL,
  `bHit` int(11DEFAULT NULL,
  `bGroup` int(11DEFAULT NULL,
  `bIndent` int(11DEFAULT NULL,
  `bStep` int(11DEFAULT NULL,
  PRIMARY KEY (`boardId`),
  KEY `board_ibfk_1` (`bUsername`),
  CONSTRAINT `board_ibfk_1` FOREIGN KEY (`bUsername`REFERENCES `boardmember` (`username`ON DELETE CASCADE ON UPDATE CASCADE
ENGINE=InnoDB AUTO_INCREMENT=133 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. boardmember

1
2
3
4
5
6
7
8
9
10
11
12
CREATE TABLE `boardmember` (
  `memberId` int(11unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(10DEFAULT NULL,
  `password` varchar(10DEFAULT NULL,
  `email` varchar(20DEFAULT NULL,
  `gender` varchar(2DEFAULT NULL,
  `joindate` datetime DEFAULT CURRENT_TIMESTAMP,
  `birthday` datetime DEFAULT NULL,
  PRIMARY KEY (`memberId`),
  UNIQUE KEY `username` (`username`)
ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. comment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
CREATE TABLE `comment` (
  `commentId` int(11NOT NULL AUTO_INCREMENT,
  `boardId` int(11DEFAULT NULL,
  `username` varchar(10DEFAULT NULL,
  `content` varchar(100DEFAULT NULL,
  `cLike` int(11DEFAULT NULL,
  `cGroup` int(11DEFAULT NULL,
  `cIndent` int(11DEFAULT NULL,
  `cStep` int(11DEFAULT NULL,
  `cDate` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`commentId`),
  KEY `username` (`username`),
  KEY `comment_ibfk_1` (`boardId`),
  CONSTRAINT `comment_ibfk_1` FOREIGN KEY (`boardId`REFERENCES `board` (`boardId`ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `comment_ibfk_2` FOREIGN KEY (`username`REFERENCES `boardmember` (`username`)
ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Algorithm time complexity  (2) 2019.12.01
자바 메모리 구조  (0) 2019.11.23
Various html  (0) 2019.11.14
Settings  (0) 2019.11.14
Controller  (1) 2019.11.14

1. home

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>Home</title>
</head>
<body>
<h1>
    Hello world!  
</h1>
${success }<br>
${session }
<P>  The time on the server is ${serverTime}. </P>
<c:choose>
    <c:when test="${session == null}">
        <a href="toLogin">login</a> &nbsp;&nbsp;&nbsp;
        <a href="toRegister">register</a> &nbsp;&nbsp;&nbsp;
    </c:when>
    <c:otherwise>
        <a href="logout">Logout</a> &nbsp;&nbsp;&nbsp;
        <a href="toRegister">register</a> &nbsp;&nbsp;&nbsp;
    </c:otherwise>
</c:choose>
<a href="boardList">게시판</a>&nbsp;&nbsp;&nbsp;
<form action="search">
    <span>검색 : </span><input type="text" name="search">&nbsp;&nbsp;
    <select name="type">
        <option value="btitle" selected="selected">title</option>
        <option value="bContent" >content</option>
    </select>
    <input type="submit" value="검색">
</form>
 
</body>
</html>
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. member

a. login

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
${fail }
<form action="loginCheck" method="post">
    <div class="container">
        <label for="username"><b>Username</b></label>
        <input type="text" placeholder="Enter Username" name="username" required><br>
    
        <label for="password"><b>Password</b></label>
        <input type="password" placeholder="Enter Password" name="password" required><br>
        
        <button type="submit">Login</button>
        <input type="checkbox" name="remember">Remember me
    </div>
    <div class="container">
        <button type="button" class="cancelbtn">Cancel</button>
        <span class="psw"><a href="findPassword">Forgot password?</a></span>
    </div>
</form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

b. register

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="register" method="post">
    <div class="container">
        <label name="username"><b>Username</b></label>
        <input type="text" name="username"><br>
        
        <label name="password"><b>Password</b></label>
        <input type="password" name="password"><br>
        
        <label name="passwordCheck"><b>Password check</b></label>
        <input type="password" name="passwordCheck"><br>
        
        <label name="gender"><b>Select gender</b></label>
        <input type="radio" name="gender" value="m">M
        <input type="radio" name="gender" value="f">F<br>
        
        <label name="email"><b>Email</b></label>
        <input type="text" name="email"><br>
        
        <label name="birthday"><b>Birthday</b></label>
        <input type="date" name="birthday"><br>
        <input type="submit" value="JOIN">
    </div>
    <div class="container">
        <a href="findPassword">Forgot Password?</a>
    </div>
    
 
</form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

c. edit

d. findpassword

 

3. board

a. boardList

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
//이전 버튼 이벤트
function fn_prev(page, range, rangeSize) {
        var page = ((range - 2* rangeSize) + 1;
        var range = range - 1;
        var url = "boardList";
        url = url + "?page=" + page;
        url = url + "&range=" + range;
        location.href = url;
    }
 
  //페이지 번호 클릭
    function fn_pagination(page, range, rangeSize, searchType, keyword) {
        var url = "boardList";
        url = url + "?page=" + page;
        url = url + "&range=" + range;
        location.href = url;    
    }
 
    //다음 버튼 이벤트
    function fn_next(page, range, rangeSize) {
        var page = parseInt((range * rangeSize)) + 1;
        var range = parseInt(range) + 1;
        var url = "boardList";
        url = url + "?page=" + page;
        url = url + "&range=" + range;
        location.href = url;
    }
</script>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@include file="../home.jsp" %>
<table border="1">
    <tr>
        <th>No.</th>
        <th>Title</th>
        <th>Writer</th>
        <th>Date</th>
        <th>Hit</th>
    </tr>
    <c:forEach var="board" items="${board}">
    <tr>
        <td>${board.boardId }</td>
        <td><a href="boardView?boardId=${board.boardId }">
        <c:forEach begin="1" end="${board.BIndent }">-</c:forEach>${board.BTitle }</a></td>
        <td>${board.BUsername }</td>
        <td>${board.BDate }</td>
        <td>${board.BHit }</td>
    </tr>
    </c:forEach>
</table>
<c:if test="${session != null }">
    <a href="boardWrite">글 쓰기</a>&nbsp;&nbsp;&nbsp;
</c:if>
<div id="paginationBox">
        <ul class="pagination">
            <c:if test="${pagination.prev}">
                <li class="page-item"><a class="page-link" href="#" onClick="fn_prev('${pagination.page}', '${pagination.range}', '${pagination.rangeSize}')">Previous</a></li>
            </c:if>
            <c:forEach begin="${pagination.startPage}" end="${pagination.endPage}" var="idx">
                <li class="page-item <c:out value="${pagination.page == idx ? 'active' : ''}"/> "><a class="page-link" href="#" onClick="fn_pagination('${idx}', '${pagination.range}', '${pagination.rangeSize}')"> ${idx} </a></li>
            </c:forEach>
            <c:if test="${pagination.next}">
                <li class="page-item"><a class="page-link" href="#" onClick="fn_next('${pagination.range}', '${pagination.range}', '${pagination.rangeSize}')" >Next</a></li>
            </c:if>
        </ul>
    </div>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

b. boardVieww

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <%@include file="../home.jsp"%>
    
    <c:if test="${board.BUsername == session.username}">
        <form action="toBoardEdit" method="post">
            <input type="hidden" value="${board.boardId }" name="boardId">
            <input type="submit" value="edit">
        </form>
        <form action="boardDelete" method="post">
            <input type="hidden" value="${board.boardId }" name="boardId">
            <input type="submit" value="delete">
        </form>
    </c:if>
    <c:if test="${session != null }">
        <form action="toBoardReply" method="post">
            <input type="hidden" value="${board.BGroup }" name="BGroup">
            <input type="hidden" value="${board.BStep }" name="BStep">
            <input type="hidden" value="${board.BIndent }" name="BIndent">
            <input type="submit" value="reply to post">
        </form>
    </c:if>
    
    <table border="1">
        <tr>
            <td>이름</td>
            <td>${board.BUsername}</td>
        </tr>
        <tr>
            <td>Title</td>
            <td>${board.BTitle}</td>
        </tr>
        <tr>
            <td>조회수</td>
            <td>${board.BHit }</td>
        </tr>
        <tr>
            <td>Time</td>
            <td>${board.BDate }</td>
        </tr>
        <tr>
            <td>Content</td>
            <td>${board.BContent }</td>
        </tr>
    </table>
    <table border="1">
        <c:forEach var="comment" items="${comment }">
        <tr>
            <td><span>${comment.username }</span></td>
            <td><span>${comment.content }</span></td>
            <td>
                <c:if test="${comment.username == session.username }">
                    <form action="deleteComment" method="post">
                        <input type="hidden" name="boardId" value="${comment.boardId }">
                        <input type="hidden" name="commentId" value="${comment.commentId }">
                        <input type="submit" value="delete comment">
                    </form>
                </c:if>
            </td>
        </tr>
        </c:forEach>
    </table>
    <form action="postComment" method="post">
        <input type="hidden" name="boardId" value="${board.boardId }">
        <input type="hidden" name="username" value="${session.username }">
        <textarea rows="5" cols="100" name="content"></textarea><br>
        <c:if test="${session.username != null }">
            <input type="submit" value="comment submit">
        </c:if>
    </form>
 
 
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

c. boardWrite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action="boardInsert" method="post">
    <input type="hidden" name="bUsername" value="${session.username }">
        <table border="1">
            <tr>
                <td>이름</td>
                <td>${session.username }</td>
            </tr>
            <tr>
                <td>Title</td>
                <td><input type="text" name="bTitle"></td>
            </tr>
            <tr>
                <td>Content</td>
                <td><textarea name="bContent" rows="30" cols="100"></textarea></td>
            </tr>
            <tr>
                <td colspan="2">
                <input type="submit" value="submit">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

d. boardEdit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="boardEdit" method="post">
    <input type="hidden" name="boardId" value="${board.boardId}">
        <table border="1">
            <tr>
                <td>이름</td>
                <td>${board.BUsername }</td>
            </tr>
            <tr>
                <td>Title</td>
                <td><input type="text" name="bTitle" value="${board.BTitle }"></td>
            </tr>
            <tr>
                <td>Content</td>
                <td><textarea name="bContent" rows="30" cols="100">${board.BContent }</textarea></td>
            </tr>
            <tr>
                <td colspan="2">
                <input type="submit" value="submit">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

e. boardReply

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action="boardReply" method="post">
        <input type="hidden" value="${board.BGroup }" name="BGroup">
        <input type="hidden" value="${board.BStep }" name="BStep">
        <input type="hidden" value="${board.BIndent }" name="BIndent">
        <input type="hidden" name="bUsername" value="${session.username }">
        <table border="1">
            <tr>
                <td>이름</td>
                <td>${session.username }</td>
            </tr>
            <tr>
                <td>Title</td>
                <td><input type="text" name="bTitle"></td>
            </tr>
            <tr>
                <td>Content</td>
                <td><textarea name="bContent" rows="30" cols="100"></textarea></td>
            </tr>
            <tr>
                <td colspan="2">
                <input type="submit" value="submit">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

4. search

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@include file="../home.jsp" %>
${result }
<table border="1">
    <tr>
        <th>No.</th>
        <th>Title</th>
        <th>Writer</th>
        <th>Date</th>
        <th>Hit</th>
    </tr>
    <c:forEach var="board" items="${result}">
    <tr>
        <td>${board.boardId }</td>
        <td><a href="boardView?boardId=${board.boardId }">
        <c:forEach begin="1" end="${board.BIndent }">-</c:forEach>${board.BTitle }</a></td>
        <td>${board.BUsername }</td>
        <td>${board.BDate }</td>
        <td>${board.BHit }</td>
    </tr>
    </c:forEach>
</table>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

'ETC' 카테고리의 다른 글

자바 메모리 구조  (0) 2019.11.23
various query  (0) 2019.11.14
Settings  (0) 2019.11.14
Controller  (1) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14

1. datasource.properties for easier database access

1
2
3
4
5
dbname=mysql
url=jdbc:mysql://localhost:3306/november11board?serverTimezone=UTC
id=****
pw=****
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. root-context.xml 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?xml version="1.0" encoding="UTF-8"?>
    
    <!-- Root Context: defines shared resources visible to all other web components -->
    <context:property-placeholder
        location="classpath:/mybatis/config/datasource.properties" />
    <context:annotation-config />
    <bean id="dataSource"
        <property name="driverClassName" value="${driver}" />
        <property name="url" value="${url}" />
        <property name="username" value="${id}" />
        <property name="password" value="${pw}" />
    </bean>
    <bean id="sqlSessionFactoryBean"
        <property name="dataSource" ref="dataSource" />
        <property name="mapperLocations"
            value="classpath:/mybatis/mappers/*Mapper.xml" />
        <property name="typeAliasesPackage"
            value="com.test.taewon.model.dto" />
    </bean>
    <bean id="sqlSession"
        class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactoryBean"></constructor-arg>
    </bean>
    <bean id="TransactionManager"
        <property name="dataSource" ref="dataSource"></property>
    </bean>
        <property name="basePackage" value="com.test.taewon.model.dao"></property>
    </bean>
</beans>
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. web.xml added filtering for language

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 
    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>
    
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>   
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>  
            <param-value>true</param-value>
        </init-param>
    </filter>    
 
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>                 
    </filter-mapping>
    
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 
    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
        
    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    
 
</web-app>
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

4. pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?xml version="1.0" encoding="UTF-8"?>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>taewon</artifactId>
    <name>november9</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE
        </org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>
 
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
 
        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>
 
        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>
 
        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
 
        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
 
        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
        <!-- JDBC Oracle -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>
 
 
        <!-- Has Simple JDBCTemplate -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.1.1.RELEASE</version>
        </dependency>
 
 
        <!-- ORM MyBatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.0</version>
        </dependency>
        <!-- Spring MyBatis lib -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.0</version>
        </dependency>
 
        <!-- CONNECTION POOL -->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
 
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.10</version>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
 
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature
                        </projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder
                        </buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

various query  (0) 2019.11.14
Various html  (0) 2019.11.14
Controller  (1) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Paging  (0) 2019.11.14

+ Recent posts