[Tomcat 설치 폴더]
├── bin # 실행 가능한 스크립트 및 실행 파일
├── conf # 구성 파일
├── lib # 톰캣 및 웹 애플리케이션에 필요한 라이브러리
├── logs # 로그 파일
├── temp # 임시 파일
├── webapps # 웹 애플리케이션 파일 (WAR 파일 및 압축 풀린 애플리케이션)
└── work # JSP 컴파일된 파일 및 임시 데이터 저장소
서블릿과 JSP 파일 만들어 보기
package com.tenco;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet(name = "echo2", urlPatterns = {"/echo2"})
public class Echo2 extends HttpServlet {
public Echo2() {
super();
}
// get 요청 방식
// http://localhost:8080/demo_3/echo2
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// request -> req(
System.out.println("doGet 메서드 호출 확인 ");
// 자바.io 객체 (스트림 통해 데이터를 넣을 예정)
PrintWriter pw = resp.getWriter();
pw.print("<!DOCTYPE html>");
pw.print("<html lang=\"en\">");
pw.print("<head>");
pw.print(" <meta charset=\"UTF-8\">");
pw.print(" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
pw.print(" <title>Document</title>");
pw.print("</head>");
pw.print("<body>");
pw.print("<section>");
pw.print("<p style=\"color: red;\" >Hello First Srvlet 반가워</p>");
pw.print("</section>");
pw.print("</body>");
pw.print("</html>");
resp.setContentType("text/html; charset=utf-8");
}
// post 요청 방식
// http://localhost:8080/demo_3/echo2
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(req, resp);
}
}
<%@ 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>
<h1>home.jsp 파일 입니다 </h1>
<p>주소 설계 : http://localhost:8080/demo_3/home.jsp</p>
</body>
</html>
[JSP] 서블릿 작성, 배포, web.xml 설정에 이해 (0) | 2024.07.02 |
---|---|
[JSP] 서블릿 Life Cycle 이란? (0) | 2024.07.02 |
[JSP] 서블릿이란? (0) | 2024.07.01 |
[JSP] WAS와 웹 컨테이너의 역할 (0) | 2024.06.28 |
[JSP] 웹 서버와 웹 애플리케이션 서버(WAS) (0) | 2024.06.28 |