JSP
[JSP]Welcome 파일 지정
dev23
2024. 8. 14. 20:47
반응형
- 웹 애플리케이션 첫 화면에 해당하는 홈페이지를 web.xml에 등록해 두면 브라우저에서는 컨텍스트 이름만으로 요청하여
간단하게 웹 페이지를 표시할 수 있다.
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>
* WebContent/WEB-INF/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" 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">
<display-name>JSP</display-name>
<welcome-file-list>
<welcome-file>/welcome/main.jsp</welcome-file>
<welcome-file>/welcome/add.jsp</welcome-file>
<welcome-file>/welcome/main.html</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/err/error_404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/err/error_500.jsp</location>
</error-page>
</web-app>
- 첫 번째 홈페이지이다.
* main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>홈페이지</title>
</head>
<body>
<h1>안녕하세요</h1>
<h1>JSP 홈페이지입니다.</h1>
</body>
</html>
- 코드 작성 후 브라우저의 주소란에 프로젝트 이름까지만 입력하여 접근해 본다.
- 개발을 모두 마치고 실제 서비스를 제공할 때는 웹 사이트에 대한 도메인 이름을 구한 후 웹 호스팅업체에서 제공하는
방법으로 브라우저에서 도메인 이름으로 요청해야 한다. 그리고 다시 컨텍스트 이름으로 재요청하도록 설정하면 된다.
반응형