티스토리 뷰
- MemoController
@RequestMapping(value = "/", method = RequestMethod.POST)
public ModelAndView postIndex(@RequestParam(value = "name")String name,
@RequestParam(value = "text")String text) {
System.out.printf("이름 : %s\n", name);
System.out.printf("내용 : %s\n", text);
ModelAndView modelAndView = new ModelAndView("memo/index");
return modelAndView;
}
- index.html
<input autofocus class="input" maxlength="10" name="name" placeholder="이름" type="text">
</label>
<label class="input-container">
<input class="input" maxlength="100" name="text" placeholder="메모" type="text">
- @RequestParam 어노테이션은 HTTP 요청 파라미터를 메서드의 파라미터로 전달받을 때 사용한다. 또 Controller 메서드의 파라미터와 웹 요청 파라미터와 맵핑하기 위한 어노테이션이라고 볼 수 있다. 첫 번째 파라미터인 name은 html의 name = "name"요청 파라미터의 값을 전달받고, 두 번째 파라미터인 text는 name="text" 파라미터 값을 전달받는다.
- index.html
<form class="form" id="form" method="POST">
- 이 부분에서 method에 POST를 넣은 이유는 무엇일까?
우선 method의 속성값으로는 GET과 POST 두 가지 중 하나를 선택할 수 있다. GET 방식은 URL에 폼 데이터를 추가하여 서버에 전달하는 방식이다. 또한, GET방식은 보통 쿼리 문자열에 포함되어 전송되므로 길이에 제한이 있다. 따라서 보안 취약점이 존재한다.
하지만 POST 방식은 폼 데이터를 별도로 첨부하여 서버로 전달하는 방식이기 때문에 HTTP 요청은 브라우저에 의해 캐시 되지 않으므로 브라우저 히스토리에 남지 않는다. 따라서 GET 보다 POST 방식을 사용하는 것이 보안적으로 유리하다.
'웹 개발 > SpringBoot' 카테고리의 다른 글
| [Spring Boot] 이메일 전송 (0) | 2022.11.07 |
|---|---|
| [String Boot] JSON (0) | 2022.11.07 |
| [String Boot] 메모장 구현 과정 (2) | 2022.11.04 |
| [String Boot] ANNOTATION 공부 (0) | 2022.11.04 |
| [Spring Boot] 프로젝트 구조 (0) | 2022.11.03 |
댓글