jsp 내장 객체

치로·2024년 9월 4일
  1. jsp 내장 객체
  • jsp 페이지 내에서 제공되는 특수한 클래스 형의 객체
  • 내장 객체는 선언과 할당 없이 사용 사용할 수 있음
  • jsp 페이지가 java 클래스 형태로 변환될 때, jsp에서 java 클래스 안에 자동으로 포함
  1. 내장 객체 종류
  • request : HttpServletRequest (웹 브라우저의 요청 정보를 저장하고 있는 객체)
  • response : HttpServletResponse (웹 브라우저의 요청에 대한 응답 정보를 저장하고 있는 객체)
  • out : jspWriter (jsp 페이지에 출력할 내용을 가지고 있는 출력 스트림 객체)
  • session : HttpSession (하나의 웹 브라우저의 정보를 유지하기 위한 세션 정보를 저장하고 있는 객체)
  • application
  • pageContext
  • page
  • config
  • exception
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% 
	// localhost:8081/first.jsp?cnt=5
	String cntStr = request.getParameter("cnt");

	int cnt = 100;
	if(cntStr !=null && !cntStr.equals("")) {
		cnt = Integer.parseInt(cntStr);
	}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%for(int i=0; i<cnt; i++) {%>
		안녕 servlet<br>
	<%}%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h3>param 액션 태그</h3>
	<jsp:forward page="param_result.jsp">
		<jsp:param value="apple" name="userid"/>
		<jsp:param value="김사과" name="username"/>
	</jsp:forward>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	아이디 : <%=request.getParameter("userid") %><br>
	<%=request.getParameter("username") %>님 어서오세요
</body>
</html>

0개의 댓글