프로그래밍/JSP

[JSP] web.xml파일을 이용해 초기 id, pw 설정 및 확인

비전공개미 2022. 10. 11. 18:55
반응형
SMALL

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
  <display-name>bit_jsp</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-param추가 / xml파일은 반영되려면 서버를 restart되야 함 -->
  <context-param>
  	<param-name>adminId</param-name>
  	<param-value>admin</param-value>
  </context-param>
  <context-param>
  	<param-name>adminPwd</param-name>
  	<param-value>1234</param-value>
  </context-param>
</web-app>

 

 

 

ex12.jsp

<%@ 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>
관리자 아이디 : <%=application.getInitParameter("adminId") %><br>
관리자 비밀번호 : <%=application.getInitParameter("adminPwd") %>
</body>
</html>
[출력]
관리자 아이디 : admin
관리자 비밀번호 : 1234

 

반응형
LIST