Christmas Pikachu Servlet - reques, response
개발일지/JSP

Servlet - reques, response

ZI_CO 2022. 11. 24.

Servlet_request_response_1.pdf
0.20MB

 

사용자에 요청과 응답을 담당하는 객체

 

- HttpServlet

- HttpServletRequest

- HttpServletResponse

 

 

 

 

HttpServletRequest - 주요 메소드

request.getCookies();
request.getSession();
request.getAttribute();
request.setAttribute();
request.getParameter();
request.getParameterNames();
request.getParameterValues();

 

httpServletResponse - 주요 메소드
response.addCookie();
response.getStatus();

 

새로운 request, response가 생성이 된다.
response.sendRedirect(getServletInfo());
response.getWriter();
response.getOutputStream(); // 바이트 단위로 처리

 

 

 

 

 

package com.boot.req;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/ms1")
public class MServlet1 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// HttpServletRequest - 주요 메소드
		request.getCookies();
		request.getSession();
		request.getAttribute("name");
//		request.setAttribute(null, null);
		request.getParameter("name");
		request.getParameterNames();
		request.getParameterValues("value");
		
		// httpServletResponse - 주요 메소드
		response.addCookie(null);
		response.getStatus();
		
		// 새로운 request, response가 생성이 된다.
		response.sendRedirect(getServletInfo());
		response.getWriter();
		response.getOutputStream(); // 바이트 단위로 처리
		
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}

'개발일지 > JSP' 카테고리의 다른 글

Servlet form 데이터 처리  (0) 2022.11.24
Servlet Life-Cycle(서블릿 생명주기)  (0) 2022.11.24
Servlet Mapping 하는방법 2가지  (0) 2022.11.23
JSP & Servlet - Servlet(기본) 2  (0) 2022.11.23
JSP & Servlet - Servlet(기본) 1  (0) 2022.11.23

댓글