spring mvc : servlet 생성
This commit is contained in:
@@ -2,7 +2,9 @@ package com.example.servlet;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||||
|
|
||||||
|
@ServletComponentScan // 서블릿 자동 등록
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ServletApplication {
|
public class ServletApplication {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.example.servlet.basic;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@WebServlet(name = "helloServlet", urlPatterns = "/hello")
|
||||||
|
public class HelloServlet extends HttpServlet {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
|
||||||
|
System.out.println("HelloServlet.service");
|
||||||
|
System.out.println("req = " + req);
|
||||||
|
System.out.println("resp = " + resp);
|
||||||
|
|
||||||
|
String username = req.getParameter("username");
|
||||||
|
System.out.println("username = " + username);
|
||||||
|
|
||||||
|
// response header 정보 추가
|
||||||
|
resp.setContentType("text/plain");
|
||||||
|
resp.setCharacterEncoding("utf-8");
|
||||||
|
|
||||||
|
// response body
|
||||||
|
resp.getWriter().write("hello " + username);
|
||||||
|
}
|
||||||
|
}
|
||||||
41
spring-mvc/servlet/src/main/webapp/basic.html
Normal file
41
spring-mvc/servlet/src/main/webapp/basic.html
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<ul>
|
||||||
|
<li>hello 서블릿
|
||||||
|
<ul>
|
||||||
|
<li><a href="/hello?username=servlet">hello 서블릿 호출</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>HttpServletRequest
|
||||||
|
<ul>
|
||||||
|
<li><a href="/request-header">기본 사용법, Header 조회</a></li>
|
||||||
|
<li>HTTP 요청 메시지 바디 조회
|
||||||
|
<ul>
|
||||||
|
<li><a href="/request-param?username=hello&age=20">GET -
|
||||||
|
쿼리 파라미터</a></li>
|
||||||
|
<li><a href="/basic/hello-form.html">POST - HTML Form</a></
|
||||||
|
li>
|
||||||
|
<li>HTTP API - MessageBody -> Postman 테스트</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>HttpServletResponse
|
||||||
|
<ul>
|
||||||
|
<li><a href="/response-header">기본 사용법, Header 조회</a></li>
|
||||||
|
<li>HTTP 요청 메시지 바디 조회
|
||||||
|
<ul>
|
||||||
|
<li><a href="/response-html">HTML 응답</a></li>
|
||||||
|
<li><a href="/response-json">HTTP API JSON 응답</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
12
spring-mvc/servlet/src/main/webapp/index.html
Normal file
12
spring-mvc/servlet/src/main/webapp/index.html
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<ul>
|
||||||
|
<li><a href="basic.html">서블릿 basic</a></li>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user