Front-end

JSP & Servlet DAY 1 ( Servlet, Apache Tomcat 실습 [ Context Path, url mapping ], Servlet 메서드 설정, HTTP 요청 테스트 [ postman ] )

도키마 2024. 7. 24. 14:05



 

 

 

 

오늘의 노래 추천 👅

 

 
Tip Toe (with 이하이)
아티스트
Crush
앨범
with HER
발매일
1970.01.01

 

어떤남자가 불러줬으면 좋 겡 당 . . . 이하이는 더 잘돼야 합니다.

 


 

 

 

 

 

 

 

 

 

 

 

 

DAY 1


 

 

 

 

 

 

 

 

ㅡ Server & Client ㅡ

Asychronouse javascript and XM

 

 

 

 

Server & Client

 

request 와 response 를 주고받음

 

ㅡ> HTTP 라는 규칙을 사용해서 서버와 클라이언트 간에 데이터를 주고받음

 

request and response

 

서버는 response 로서 HTML, XML, 출력 결과 등을 전송

 

 

 

 

ㅡ 정적 웹서버 ㅡ

웹 서버에 미리 저장된 파일이 그대로 전달

저장파일이 변하지않는 이상 같은 출력

Static Web Page

 

 

ㅡ 동적 웹서버 ㅡ

웹 서버의 데이터를 스크립에 의해 가공처리 후 생성되어 전달

* 사용자, 시간, 요청에 따라 상이한 출력

Dynamic Web Page

 

 

 

 

Server-side Programming

Client - Server 구조에서 Server에서 실행되는 소프트웨어

 

 

 

 

 

 

 

 

ㅡ Servlet ㅡ

Server + Java Applet

 

Servlet

 

 

 

 

* Servlet 특징

 

1. 플랫폼 독립적 : Java 로 작성되어 어떤 플랫폼에서든 실행가능

2. 여러 Client 요청 동시처리 가능 : 웹 서버에 의해 인스턴스화 및 여러 스레드 생성

3. HttpServlet 클래스 상속받음**

 

 

 

 

 

 

 

 

ㅡ WAS ㅡ

Web Application Server

 

WAS, CGI

 

was 구조

 

Servlet 은 HTML 을 뽑아내는 기계래요 ㅠㅠ

 

was 구조

 

ㅡ> 서버 부하와 보안 등의 문제로 인해 정적 컨텐츠와 동적 컨텐츠를 분리

 

 

 

 

 

 

 

 

ㅡ CGIㅡ

Common Gateway Interface

 

WAS, CGI

 

Process ㅡ> 동적 상태 프로그램 / 운영체제가 메모리 등의 필요 자원을 할당 받은 상태

thread ㅡ> Process가 할당받은 자원을 이용하는 실행 단위

 

WAS 는 멀티 스레드를 사용하지만,

ㅡ> CGI 는 요청마다 Process 를 돌리기 때문에 요청이 많을 경우 메모리가 금방 부하됨

 

 

 

 

 

 

 

 

 

apache tomcat 과 eclipse 다운

 

https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/2024-03/R/eclipse-jee-2024-03-R-win32-x86_64.zip&mirror_id=1248

 

Thank You for Downloading Eclipse | The Eclipse Foundation

The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 415 open source projects, including runtimes, tools and frameworks.

www.eclipse.org

https://tomcat.apache.org/download-90.cgi

 

Apache Tomcat® - Apache Tomcat 9 Software Downloads

Welcome to the Apache Tomcat® 9.x software download page. This page provides download links for obtaining the latest version of Tomcat 9.0.x software, as well as links to the archives of older releases. Unsure which version you need? Specification version

tomcat.apache.org

 

 

tomcat 파일

 

eclipse server

 

apache tomcat

 

tomcat 폴더 선택

 

Port Number 수정

 

server start

 

ㅡ 문자 인코딩 (character encoding) ㅡ

 

window preferences

 

UTF-8

 

dynamic web project

 

 

 

 

ㅡ Servlet 생성 ㅡ

 

servlet 생성

 

 

 

 

ㅡ Context Path ㅡ
* context path - 서버에 올릴 프로젝트의 고유한 식별자 name

 

ㅡ url mapping ㅡ

실제 Java Class 이름 대신 Servlet 을 요청하기 위한 문자열을 Servlet Class 와 Mapping 시키는 것

ㅡ> url 길이를 축소와 보안을 위해서

 

url mapping

 

url mapping

 

 

 

 

ㅡ Servlet 메서드 재정의 ㅡ

실제 Java Class 이름 대신 Servlet 을 요청하기 위한 문자열을 Servlet Class 와 Mapping 시키는 것

 

메서드 재정의
메서드 선택

 

 

 

 

WAS 에서 Servlet 은 war 형태의 압축파일을 받아야함

이걸 Eclipse가 대신 해준 것 confiured 에 있는 war 파일

 

WAR

 

 

 

 

 

 

 

 

 

 

ㅡ url mapping 변경해보기 ㅡ

 

url mapping

 

1. Annotation : url mapping 을 Ex01Servlet 에서 sohui 로 변경 ㅡ> WebServlet 괄호 안에서 변경

2. web.xml 이용하기

 

url mapping 변경 완료

 

 

 


ㅡ context path 이름 변경해보기 ㅡ

 

modules

 

서버 더블클릭 후 modules 선택

 

context path

 

context path 이름을 Ex01Servlet 에서 ContextPah 로 변경

접속완료

 

@WebServlet("/sohui")
public class Ex01Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public Ex01Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	public void init(ServletConfig config) throws ServletException {
		System.out.println("초기화 시작");
	}

	
	public void destroy() {
		System.out.println("destroy");
	}

	
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("서비스 시작");
	}

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("doget 시작");
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("dopost 시작");
		doGet(request, response);
	}

 

 

 

 

 

 

 

 

ㅡ Servlet Life Cycle ㅡ

Servlet 객체 생성부터 소멸 과정

servlet life cycle

 

 

 

 

 

 

 

 

 

 

ㅡ HTTP 요청 테스트 해보기 ( postman 활용 ) ㅡ

 

http 요청 테스트

 

 

postman api 다운로드

 

https://web.postman.co/home

 

get started

 

home 에서 new request 선택

 

url send

 

서비스 시작

 

postman 이 클라이언트로서 request 를 보낸것

* doget, dopost 메서드 실행을 위해서는 serive 메서드 주석처리

 

선생님 콘솔에 보내기

 

도메인 주소 : 네트워크 / url

 




 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 



 

 

 

 

 

 

BYE