Servlet Flow

Servlet 

Generic Servlet 

HttpServlet

아래에서 위로 상속을 받는다.

Servlet은 HttpServlet을 상속받는데 extends HttpServlet을 해줘야한다.

그 사이에 Generic Servlet이라는 abstract가 존재하는데 사실 잘 모르겠다.


GET & POST

GET : URL 뒤쪽에 정보가 붙어 전송된다. -> 보안에 약하다.

POST : Header을 이용해 정보를 전송한다. -> 보안에 강하다.(강하다고 해야할지..)


doGet()

form 태그의 method="get" 일 경우 doGet()이 호출 된다.

인자는 HttpServletRequest, HttpServletResponse 를 받는다.(doPost도 마찬가지.)


doPost()

form 태그의 method="post"일 경우 doPost()가 호출된다.

인자는 doGet과 동일 하다.


Servlet 작동 순서

웹 -> 웹서버(WS) -> 웹 어플리케이션 서버(WAS) -> Servlet Container 

Servlet Container에서도 첫번째로 작동하는 것은 스레드 생성. 두번째는 Servlet 객체를 생성하는 것이다.


Servlet LifeCycle


Servlet은 응답속도가 빠른편이라 사용률이 높다.


왜 속도가 빠른가?

Servlet은 요청을 받아 객체가 생성되면 그 뒤로 객체를 재활용 하기 때문.(메모리에 로딩이 된다.)

       Servlet 객체 생성

       init() 호출

       service(), doGet(), doPost()호출

       destroy() 호출

위 표에서 진행 방향은 위 -> 아래 이다.

Servlet객체를 생성하면 init함수를 호출한다. 

init함수는 객체가 가지고 있어야할 정보를 가져오거나 준비하는 역할이다.

따라서 Servlet객체는 재활용 되므로 한번만 실행된다. ( Servlet객체 생성도 한번, init도 한번)

service(), doGet(), doPost()는 웹에서 호출하면 계속해서 함수가 불려진다.

destroy()함수는 마지막에 Servlet객체를 메모리에서 해제 시킬 때 한번 호출된다.


'Web' 카테고리의 다른 글

React와 Express 연동하기(1)  (0) 2020.09.11
IntelliJ에서의 Servlet 프로젝트 설정 방법  (0) 2019.09.19
젠킨스 사용해보기  (0) 2017.12.31
Servlet 기초(2)  (0) 2016.11.11


같은 GameObject(Prefab)를 여러개 만들때 관리 방법

유니티를 공부하다가 wall을 여러개 만들고 SetActive()를 사용해서 비활성화 후

시간에 따라 벽을 차례대로 활성화 시키려고 했다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    using UnityEngine;
    using System.Collections;
 
    public class MakeWall_Enable : MonoBehaviour {
        // Use this for initialization
        public GameObject prefab;
        void Start () {
            for(int i=0; i<5;i++){
                Instantiate(prefab, new Vector3 (0, Random.Range (-10.0f, 10.0f), 0), Quaternion.identity);
                prefab.SetActive (false);
            }
 
        }
        
        // Update is called once per frame
        void Update () {
        
        }
    }
 
cs



위 코드를 작성하고 나니 각 프리팹을 어찌 컨트롤 할지 고민이라 하나의 리스트를 만들려고 했다.

..사실 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    using UnityEngine;
    using System.Collections;
 
    public class MakeWall_Enable : MonoBehaviour {
        // Use this for initialization
        public GameObject[] prefab = new GameObject[5];

        void Start () {
            for(int i=0; i<5;i++){
                Instantiate(prefab[i], new Vector3 (0, Random.Range (-10.0f, 10.0f), 0), Quaternion.identity);
                prefab[i].SetActive (false);
            }
 
        }
        
        // Update is called once per frame
        void Update () {
        
        }
    }
 
cs


이렇게 작성했더니 

Out of Range 오류를 내뱉어서 황당했다.


stackoverflow에 들어가 검색을 해봤더니 이러한 현상을 가진 분들을 많이 봤다.

해결방법도 많아보였지만 현재 내가 배운 지식으로는 어림도 없을 것 같아서 간단한 방법을 사용했다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
 
    public class MakeWall_Enable : MonoBehaviour {
        // Use this for initialization
        public GameObject prefab;
        List<GameObject> wallList = new List<GameObject>();
        void Start () {
            for(int i=0; i<5;i++){
                Instantiate(prefab, new Vector3 (0, Random.Range (-10.0f, 10.0f), 0), Quaternion.identity);
                wallList.Add (prefab.gameObject);
                prefab.SetActive (false);
            }
 
        }
        
        // Update is called once per frame
        void Update () {
        
        }
    }
 
cs


List를 하나 만들어서 프리팹을 관리하는 법이다.

SetActive를 하면 Fine("")함수로는 찾을 수 없어서 애초에 prefab을 생성하면서 List에 추가 해줬다.

MySQL을 설치 한 후 다음 명령어를 사용하여 로그인을 해준다.(비밀번호는 설치하는 도중에 알려준다.)


cd /usr/local/mysql/bin

- sudo ./mysql -u root -p

- 패스워드 입력


로그인이 완료 되면 비밀번호를 바꿔준다.


- use mysql;

- update user set password = password('비밀번호') where user = 'root';

- flush privileges;


따단. 이러면 비밀번호 변경이 완료된다.


* 간혹가다가 use mysql; 명령어를 치면

You must reset your password using ALTER USER statement before executing this statement

ㅇㄴㅁㅇㄴㅁㅇㄴㅁㄴㅁㅇmysql] root 비밀번호 변경 - 리눅스기준|작성자 천금채

라는 오류가 나오기도한다.


이때 해결법은


- alter user 'root'@'localhost' identified by '비밀번호';

- flush privileges;


로 하면 된다.

+ Recent posts