이번에도 web.xml에 파라미터를 정의하고 jsp페이지에서 불러오는 예제를 만들어봅시다.
LoadParam.jsp 파일과 web.xml 파일을 만들어야합니다.
LoadParam.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
String name = getInitParameter("MY_NAME");
%>
이름 출력 : <%= name %> <br>
</body>
</html>
web.xml
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>my-jsp</servlet-name>
<jsp-file>/LoadParam.jsp</jsp-file>
<init-param>
<param-name>MY_NAME</param-name>
<param-value>gakari</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>my-jsp</servlet-name>
<url-pattern>/LoadParam.jsp</url-pattern>
</servlet-mapping>
</web-app>
실행 화면
web.xml 에 파라미터로 정의한 값이 그대로 보임을 알 수 있습니다.
'프로그래밍 > JSP Servlet' 카테고리의 다른 글
JSP/Servlet - 익스프레션 언어 (애트리뷰트 및 param, paramValues) (0) | 2016.01.06 |
---|---|
JSP/Servlet - setAttribute, getAttribute, removeAttribute 메소드에 사용법 (0) | 2016.01.05 |
JSP/Servlet - 웹애플리케이션 초기화 파라미터 (0) | 2016.01.05 |
JSP/Servlet - 서버 및 서블릿 환경 정보 가져오기(ServletContext) (0) | 2016.01.05 |
JSP/Servlet - jspInit 메소드와 jspDestroy 메소드 활용 (0) | 2016.01.04 |
JSP/Servlet - 서블릿 초기화 파라미터 (0) | 2016.01.04 |
JSP/Servlet - init 메소드와 destroy 메소드 사용하기 (0) | 2016.01.03 |
JSP/Servlet - 익셉션(exception) 타입별로 에러페이지 등록하기 (0) | 2016.01.02 |