[JSP] 웹에서 데이터 SCOPE 관련 : request, response, session, application

heegon·2025년 8월 29일

목록 보기
3/18

📌 request

  • 사용자 요청과 관련된 정보 처리
  • 다음 페이지까지만 데이터 전송 가능

request.getParameter() -> 레디오박스, 텍스트입력창 과 같이 한 가진 값이 선택되는 경우에 사용

request.getParameterValues() -> 체크박스와 같이 여러 값이 선택되는 경우에 사용

getParameter() 사용 예시

.html
<input type="text" width="5" name="username">

.html

<select name="job">
	<option>무직</option>
	<option>학생</option>
	<option>주부</option>
	<option>직장인</option>
	<option>프리랜서</option>
</select>

.jsp
<%= request.getParameter("job") %>

getParameterValues() 사용 예시

.html

<input type="checkbox" value= "A" name="interest">A
<input type="checkbox" value= "B" name="interest">B
<input type="checkbox" value= "C" name="interest">C
<input type="checkbox" value= "D" name="interest">D

.jsp

값 저장

<% 
	String[] interests = request.getParameterValues("interest");
%>

값 출력

<%
	if(interest != null) {
    	for (String i : interests) {
        	out.print(i)
        }
    }
%>

📌 response

  • 요청에 대한 응답을 웹 브라우저로 보내주는 객체

response.sendRedirect("다른페이지.jsp") -> 현재 페이지에서 다른 페이지로 이동


📌 session

  • 하나의 브라우저 내에서 정보를 유지하기 위한 HTTP 세션 정보를 저장
  • 클라이언트와의 지속적인 연결 유지를 위한 세션 처리
  • 로그인 같은 기능에 사용

session 관련 메소드

session.setAttribute("id", "홍길동")
session.getAttribute("id")

session.getId()
session.getMaxInactiveInterval()


📌 application

서버 자원정보관련 메소드

application.getServerInfo() -> 서버 정보 확인

application.getMajorVersion()
application.getMinorVersion()

application.setAttribute("username", "홍길동")
application.getRealPath("파일명") -> 서버의 실제 파일경로
application.log("username=홍길동") -> 로그 찍는 기능

profile
❤️

0개의 댓글