내장 객체(Implicit Variable)
☞ JSP에서 기본적으로 제공해 주는 객체
☞ 변수의 선어느 객체의 생성, 할당 없이 JSP 태그에서 사용할 수 있는 객체
☞ JSP가 서블릿으로 변환될 때 Web Container가 생성해서 제공
☞ 종류
◎ request : HttpServletRequest
◎ response : HttpServletResponse
◎ out : JspWriter - Servlet에서의 PrintWriter 역할
◎ session : HttpSession - <% @ page session="false" %>로 설정하면 안생긴다.
◎ application : ServletContext
◎ config : ServletConfig
◎ pageContext : Servlet에는 없는 객체로 다른 내장 객체들을 생성할 수 있다.
◎ page : this - 서블릿 객체 자신
◎ exception : Throwable - <% @ page isErrorPage = "true" %>로 설정된 경우만 생성(default는 false)
web.xml
☞ folder : WebContent
소스보기
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>myjsp</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- Context 초기화 파라미터 - 웹어플리케이션에 존재하는 어떤 서블릿이나 JSP 모두 호출가능
JSP에서 application.getInitParameter(param-name)을 통해 조회 가능 -->
<context-param>
<param-name>name</param-name>
<param-value>Context 초기 파라미터</param-value>
</context-param>
<!-- JSP 설정 -->
<!-- Config 초기화 파라미터 - 서블릿 상에서 호출시 사용가능
<init-param>항목을 표시하는 서블릿만 호출 가능
config.getInitParameter(param-name)을 통해 조회 가능 -->
<servlet>
<servlet-name>init param</servlet-name>
<jsp-file>/implicit_var/init_param.jsp</jsp-file>
<init-param>
<param-name>name</param-name>
<param-value>Config 초기 파라미터</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>init param</servlet-name>
<url-pattern>/init_param</url-pattern>
</servlet-mapping>
</web-app>
init_param.jsp
☞ folder : WebContent/implicit_var
소스보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
초기 파라미터 조회<br>
Config초기파라미터 : <%=config.getInitParameter("name") %><br>
Context초기파라미터 : <%=application.getInitParameter("name") %>
</body>
</html>