Preloader image
DDD

자바

최초 프로젝트 생성 시 Servlet 사용 설정

작성자 관리자 (admin)
조회수 531
입력일 2022-11-14 23:30:17

- pom.xml

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

위와 같이 설정해 주면

@Controller 선언 후 @RequestMapping 를 사용 할 수 있다.

예제)

package com.example.demo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class DemoApplication {

    @RequestMapping(value = "/main", method = { RequestMethod.POST, RequestMethod.GET })
    public String main(@RequestParam(value = "name", defaultValue = "World") String name
            , ModelMap                model
            , HttpServletRequest    request
            , HttpServletResponse  response
            , HttpSession           session
    )
    {
        System.out.println("main ~ !!!!");
        model.addAttribute( "page", "LeeDAEBEOM");
        return "/main";
    }

    @RequestMapping(value = "/corell/{mode}/{bif_code}/{bif_num}", method = { RequestMethod.POST, RequestMethod.GET })
    public String Dynamic_board_manager_form
    (
        ModelMap                      model ,
        @PathVariable      String      mode ,
        @PathVariable      String  bif_code ,
        @PathVariable      String   bif_num
    )
    throws Exception
    {
        model.addAttribute( "a", mode     );
        model.addAttribute( "b", bif_code );
        model.addAttribute( "c", bif_num  );

        return "/index";
    }

}

- index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<% pageContext.setAttribute("LF", "\n"); %>
<!DOCTYPE html>
<html>
<head>
<meta charset="uth-8">
<title>Jsp page sample</title>
</head>
<body>
<pre>
    
    ===============
    jsp body sample
    ===============
    INDEX -
    ---------------- 
    ${a}
    ------------
    ${b}
    ----------------    
    ${c}
    ----------------

    <a href="#">Digital2u</a>

</pre>
</body>
</html>

- http://127.0.0.1:8080/corell/%EB%84%88%EC%9D%98/%EC%82%AC%EB%9E%91%EC%9D%84/%EC%9B%90%ED%95%B4

  
    ===============
    jsp body sample
    ===============
    INDEX -
    ---------------- 
    너의
    ------------
    사랑을
    ----------------    
    원해
    ----------------

    Digital2u

^