Deveolpment Study๐๏ธ/Spring Framework
[Spring] @RequestMapping _ GET๋ฐฉ์, POST ๋ฐฉ์
bompeach
2023. 6. 5. 20:17
JSP์์ ์ปจํธ๋กค๋ฌ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ณด๋๋๋ฐ null๊ฐ์ด ๋จ๋ ์ด์ ๊ฐ ๋ฌด์์ธ์ง ์์นํ๋ค๊ฐ ์๊ฒ ๋๊ฑฐ ์ ๋ฆฌ~
๊ทธ์ค์ ๋ด ๊ฒฝ์ฐ์ ํด๋นํ๋ ์ด์ !
โ์์ฒญ์ด POST ๋ฐฉ์์ด ์๋ GET ๋ฐฉ์์ผ๋ก ์ ๋ฌ๋์๋์ง ํ์ธํด๋ณด๊ธฐโ
@RequestMapping ์ด๋
ธํ
์ด์
์ ์ฌ์ฉํ ๋, ๊ธฐ๋ณธ์ ์ผ๋ก GET ๋ฐฉ์์ผ๋ก ์์ฒญ์ ์ฒ๋ฆฌํ๋ค. ๋ฐ๋ผ์, ์์ฒญ์ POST ๋ฐฉ์์ผ๋ก ์ ๋ฌํ๋ ค๋ฉด @RequestMapping ์ด๋
ธํ
์ด์
์ method ์์ฑ์ ์ถ๊ฐํ์ฌ POST ๋ฐฉ์์ ๋ช
์ํด์ผํ๋ค.
JSP์์ POST ๋ฐฉ์์ผ๋ก ๋ณด๋ด๋ ์ฝ๋
var form = document.createElement("form");
form.setAttribute("charset", "utf-8");
form.setAttribute("method", "POST"); //POST ๋ฐฉ์
form.setAttribute("action", "/reservation.do");
--์ค๋ต--
์ปจํธ๋กค๋ฌ์์ POST ๋ฐฉ์ ๋ฐ๊ธฐ!
@RequestMapping ์ด๋ ธํ ์ด์ ์ method ์์ฑ์ ์ถ๊ฐํ์ฌ POST ๋ฐฉ์์ ๋ช ์ํ๋ ๋ฐฉ๋ฒ
@RequestMapping(value = "/reservationForm.do", method = RequestMethod.POST)
public String reservationForm(Model model, HttpServletRequest request) throws Exception {
// ๋ฉ์๋ ๋ด์ฉ
}
method = RequestMethod.POST ์ด๋ ๊ฒ ๋ฐ์์ฃผ๋ฉด ๊ฐ์ด ์ ๋์ด์ค๋ ๊ฒ์ ํ์ธํ ์ ์๋ค!