JSP practice_240419

Choi Suyeon·2024년 4월 19일

JSP 요청

GET, POST방식 요청
직접요청, <a>, location, <form>사용하여 요청.
_jspService method가 모든 요청방식을 받는다.

내장객체

_jspService method안에 선언되어있는 객체들.
JSP tag's 중 scriptlet(<% %>)과 expression(<%= %>)에서 사용할 수 있는 객체.

request

데이터 형 : HttpSerbletRequest

접속자의 정보얻기
요청 Web Parameter
forward를 사용한 페이지이동(RequestDispather)
관계유지객체 얻기(HttpSession Cookie)
forward로 이동할 페이지에서 사용할 값 저장, 관리

response

데이터 형 : HttpServletResponse

응답방식의 설정(MIME-types 설정)
redirect로 페이지 이동
download
Cookie 심기

session

데이터 형 : HttpSession

관계유지
접속자 별로 데이터를 저장, 관리

out

데이터 형 : JspWriter

웹 브라우저로 출력

application

데이터 형 : ServletContext

모든 접속자가 사용하게 될 공통 값을 저장, 관리

pageContext

데이터 형 : PageContext

접속한 페이지에서만 사용하게 될 값을 저장, 관리

exception

데이터 형 : Throwable

예외처리시 사용.
Page directive의 isErrorPage="true"인 설정에서만 제공되는 내장객체
  • Scope 객체 : 접속자가 사용하는 값을 저장하고, 관리하는 객체
    범위 : pageContext > request > session > application

request 내장객체

javax.servlet.http.HttpServletRequest가 데이터 형인 객체.

접속자의 요청정보
web상에 존재하는 자원을 요청할 때에는 URL을 사용.

URL     Domain name &/ URI                  ?  : GET방식에만 존재
protocol/server name/       /servlet path   ? QueryString
http://localhost:80/jsp_prj/day0419/test.jsp?이름=값&이름=값
  • 요청방식 : request.getMethod()
  • 요청URL : request.getRequestURI()
  • 요청Protocol : request.getProtocol() //HTTP1.1
  • 요청 서버명 : request.getServerName()
  • 요청 서버 포트 : request.getServerPort()
  • 요청 URI : request.getRequestURI()
  • 요청 파일(자원)경로 얻기 : request.getServletPath()
  • 접속자 ip주소 : request.getRemoteAddr()
  • 접속자 port : request.getRemotePort()
  • QueryStirng 얻기 : request.getQueryString()
  • web parameter(요청 값)얻기 : request.getParameter("이름")
    //이름이 중복된다면 가장 앞의 web parameter만 얻어온다.
  • web parameter명이 중복된 값 얻기 : String[] data = request.getParameterValues("이름");
    //QueryString에서 이름 같은 모든 parameter를 얻는다.

0개의 댓글