inblog logo
|
harimmon
    스프링부트

    [스프링부트] 9. request객체 2

    백하림's avatar
    백하림
    Mar 19, 2025
    [스프링부트] 9. request객체 2
    Contents
    FrontController

    jsp파일을 요청했을 때 일어나는 일

    <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <h1>Home Page</h1> <hr> <% String name = "홍길동"; %> <%=name%> </body> </html>
    notion image
    notion image
    notion image

    FrontController

    notion image
    package org.example.demo8; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; // localhost:8080/hello.do?path=a @WebServlet("*.do") public class FrontController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("common logic"); String path = req.getParameter("path"); if (path.equals("a")) { req.getRequestDispatcher("a.jsp").forward(req, resp); } else if (path.equals("b")) { req.getRequestDispatcher("b.jsp").forward(req, resp); } else if (path.equals("c")) { req.getRequestDispatcher("c.jsp").forward(req, resp); } else { } } }
    💡
    주소창에 localhost:8080/hello.do?path=a
    <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <h1>A view</h1> </body> </html>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <h1>B view</h1> </body> </html>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <h1>C view</h1> </body> </html>
    notion image
    notion image
    notion image
    Share article

    harimmon

    RSS·Powered by Inblog