본문 바로가기
IT/Spring Boot

SpringBoot프로젝트에 JSP 프로그래밍 추가 하기

by 골든크랩 2022. 9. 29.
728x90
반응형

JSP 프로그래밍은 webapp 라는 특별한 디렉토리에서 진행해야 하므로 이것부터 만들어준다.

 

1. src/main 아래 webapp 생성

 

2. webapp 아래 jsp 파일 생성

 

3. 필요라이브러리 추가. build.gradle 에 다음 내용 추가

runtimeOnly  'org.apache.tomcat.embed:tomcat-embed-jasper:'
runtimeOnly  'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api'

 

4.  jsp 코딩

예제)

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String requestName = request.getParameter("name");
    String servletName = config.getServletName();
%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title> JSP 기초 </title>
</head>
<body>
    <h2><%= requestName %> Hello World! - TEST</h2>
    <h2> 나는 <%= servletName %> 이란다!!! - TEST</h2>
</body>
</html>

 

5. 테스트...URL 에 jsp 파일명을 바로 쓰고 접근

http://localhost:9090/HelloJsp.jsp?name=%22%EB%82%98%EB%82%98%22

728x90
반응형

댓글