[JSP] JSP 기본

JSP는 Java Server Page이다.

html 코드 내에 Java의 코드가 삽입되어 있다고 생각하면 쉽다.
그래서 JSP 파일도 html 코드와 상당히 유사한데 실행되는 과정은 좀 특이하다.

1) Web Browser에서 JSP를 요청한다. (localhost/example/index.jsp)

2) JSP는 Servlet으로 변환이 되어 실행된다. 이 과정에서 index.jsp는 java 소스가 되어(정확히는 Servlet이 되는 것이다) .java의 확장자를 가진 파일로 변경이 되고 jsp는 파일명 뒤에 언더바와 함께 붙는다.
(index_jsp.java)

3) 생성 된 Servlet은 메모리에 상주하기 위해 다시 class 형태로 변모하고 메모리에 상주하기 시작한다. (index_jsp.java가 index_jsp.class가 된다. 따라서 서버 내 디렉토리에도 index_jsp.java, index_jsp.class 모두 볼 수 있다.)

4) index_jsp.class는 웹 브라우저에게 html형태로 응답을 준다.

즉, jsp가 바로 응답하는게 아니라 Servlet으로 클래스로 변환 된 뒤에 나온 결과를 html 형태로 전달하는 것이다.


Then why? any pros?

My opinion is Yes. Think about how Servlet works. Servlet creates its object when it is first initialized. And the Servlet object stays on memory unless the server is terminated or someone modifies the code to restart the server.

When the JSP is first called, it has go through all four steps like I wrote above to be a Servlet file, which means it doesn't need to compile and be 'Class' again from the second call.
All it needs to do is just making a new thread and reuse the object that is created at first call.

So it is faster than other CGI Language (specifically Perl)

댓글

이 블로그의 인기 게시물

로컬 Tomcat 서버 실행속도 개선

2019.05.23 - SQLAlchemy 의 객체 상태 관리 (expire, refresh, flush, commit) 에 관한 이해

2020.02.17 Python의 multiprocessing 중 Pool.map(), chunksize에 관한 내용