내장객체(Implicit Object)
JSP페이지에서 사용할 수 있도록 JSP컨테이너에서 미리 정의된 객체
별도의 import문 없이 자유롭게 사용 가능
종류
- request
요청정보 저장 - response
응답정보 저장 - out
출력 스트림 - session
동일한 웹브라우저에서 저장 - application
다른 웹브라우저 끼리의 저장 - pageContext
정보저장 - page
페이지 자체 - config
설정정보 - exception
예외 발생 처리
request 내장 객체
request.jsp
form을 통해 process.jsp로 name 값을 보내는 jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Implicit Objects</title>
</head>
<body>
<!--
form 페이지
요청URL : process.jsp
요청파라미터 : name=이름(input양식 name = value)
요청방식 : post
-->
<!--
action 기본값 현재 페이지(request.jsp)
method 기본값 get
-->
<form action="process.jsp" method="post">
<!-- 폼데이터 -->
<p>
<label>이름</label>
<!-- required : 필수 입력 -->
<input type="text" name="name" required="required" placeholder="이름"/>
<input type="submit" value="전송"/>
</p>
</form>
</body>
</html>
process.jsp
이전 페이지에서 보낸 파라미터를 request 내장객체로 받아 출력하는 jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<!--
요청URL : process.jsp
요청파라미터 : name=이름(input양식 name = value)
요청방식 : post
-->
<%
//내장객체.메서드(인코딩)
request.setCharacterEncoding("UTF-8");
// 변수 내장객체.폼페이지에서 입력된 데이터를 전달하는 요청파라미터값을 가져오는 메서드
String name = request.getParameter("name"); %>
<p>이름 : <%=name %></p>
</body>
</html>
'JAVA > JSP_Spring' 카테고리의 다른 글
[JSP] 구현 (0) | 2024.06.28 |
---|---|
[JSP] 디렉티브 태그 (0) | 2024.06.25 |
[JSP] OT (설정) / 스크립트 태그 (0) | 2024.06.24 |