โถ ์ค๋ ๊ณํ
=> ๊ณต๋ถ ๊ด๋ จ
1) ์์ ๋ด์ฉ ๋ณต์ต
2) MVC ๊ฐ์ฒด์งํฅ ๋ฆฌํฉํ ๋ง
3) ์คํ๋ง ๊ฐ์ ์๊ฐ ๋ชฉํ 8,9๊ฐ
โถ ๋ฌธ์ ์ ๋ฆฌ
โ MVC ๋ฆฌํฉํ ๋ง โ
1. enum๋ view์ ์์กดํ๋ฉด ์๋๋ค.
public class Controller {
// ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ง๊ณ ์๋ ํ๋
private Result result;
// play ๋ฉ์๋
public void playRsp(Rsp playerRsp) throws RspException {
// ์ฌ์ฉ์ ๊ฐ์ฒด ์์ฑ
final Player player = new Player(playerRsp);
// ๊ฒ์๊ฒฐ๊ณผ ๋ฐํ๊ฐ์ ํ๋์ ์ ์ฅ
this.result = player.play();
// ๊ฐ์๋ฐ์๋ณด ์ํ ๊ฐ ์ถ๋ ฅ
ViewOutput.whatYouInput(player.getRsp(), player.getComputer().getComRsp());
gameCount();
resultChange();
}
// ์น๋ฆฌ ๋ฌด์น๋ถ ์นด์ดํธ ๋ณํ ๋ฉ์๋
public void gameCount() {
Result.gameCount(result);
}
// viewOutput ๊ฒฐ๊ณผ ๋ฐ๊ฟ์ฃผ๊ณ ์ถ๋ ฅํ๋ ๋ฉ์๋
public void resultChange() {
if (result == Result.WIN)
ViewOutput.singleGameResult(PrintGameResult.of(result));
if (result == Result.DRAW)
ViewOutput.singleGameResult(PrintGameResult.of(result));
if (result == Result.LOSE)
ViewOutput.singleGameResult(PrintGameResult.of(result));
}
// ๊ฒ์ ๊ฒฐ๊ณผ ๋ฐํ ๋ฉ์๋
public Result gameResult() {
return result;
}
}
=> ์ปจํธ๋กค๋ฌ์ ๋ก์ง์ ์ด๊ด ํ view๋ก ํด๊ฒฐ
public static PrintGameResult of(Result result) {
switch (result) {
case WIN:
return WIN_RESULT;
case DRAW:
return DRAW_RESULT;
default:
return LOSE_RESULT;
}
}
=> ๋ก์ง ๋์ ์์ ๋ฐํ of ๋ฉ์๋๋ก ํด๊ฒฐ
2. ๋ชจ๋ธ๋ผ๋ฆฌ์ ์์กด์ ํ์ง๋ง๊ณ ์ธ๋ถ์์ ์ฃผ์ ์์ผ๋ผ (์์กด ๊ด๊ณ ใดใดใด)
// setter ๋์ ์์ฑ์๋ก ๋์
์์ผ์ ํด๊ฒฐ
// ์ปดํจํฐ ์ธ์คํด์ค๋ฅผ ์์ฑ ์ ์๋ ์ซ์(๊ฐ์๋ฐ์๋ณด) ์ ์ฅ
public Computer(final int comRsp) {
this.comRsp = comRsp;
}
=> ์ธ๋ถ์์ ์ปดํจํฐ ์ธ์คํด์ค ์์ฑ ์ ์๋์ซ์ ๊ฐ์๋ฐ์๋ณด๋ฅผ ๋งค๊ฐ๋ณ์๋ก ์๋ ์ธ์ ์
// ๊ฒ์ ์คํ!
controller.playRsp(ViewInput.inputPlayerRsp(), new Computer(new ComputerNumber().getComputerNumber()));
=> ์๊ฒ ์ปดํฐ ์ธ์คํด์ค ์์ฑ์ธ๋ฐ ๋งค๊ฐ๋ณ์์ ๊ฐ์ฒด ๋ฃ์
public class Controller {
// ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ง๊ณ ์๋ ํ๋
private Result result;
// play ๋ฉ์๋
public void playRsp(Rsp playerRsp, Computer computer) throws RspException {
// ์ฌ์ฉ์ ๊ฐ์ฒด ์์ฑ
final Player player = new Player(playerRsp);
// ๊ฒ์๊ฒฐ๊ณผ ๋ฐํ๊ฐ์ ํ๋์ ์ ์ฅ
this.result = gameOf(player, computer);
// ๊ฐ์๋ฐ์๋ณด ์ํ ๊ฐ ์ถ๋ ฅ
ViewOutput.whatYouInput(player.getRsp(), computer.getComRsp());
gameCount();
resultChange();
}
// ์น๋ฆฌ ๋ฌด์น๋ถ ์นด์ดํธ ๋ณํ ๋ฉ์๋
public void gameCount() {
Result.gameCount(result);
}
// viewOutput ๊ฒฐ๊ณผ ๋ฐ๊ฟ์ฃผ๊ณ ์ถ๋ ฅํ๋ ๋ฉ์๋
public void resultChange() {
if (result == Result.WIN)
ViewOutput.singleGameResult(PrintGameResult.of(result));
if (result == Result.DRAW)
ViewOutput.singleGameResult(PrintGameResult.of(result));
if (result == Result.LOSE)
ViewOutput.singleGameResult(PrintGameResult.of(result));
}
// ๊ฒฐ๊ณผ ์ป์ด์ค๋ ๋ฉ์๋
public Result gameOf(Player player, Computer computer) throws RspException {
return Result.getGameResult(player.getRsp(), computer.getComRsp());
}
// ๊ฒ์ ๊ฒฐ๊ณผ ๋ฐํ ๋ฉ์๋
public Result gameResult() {
return result;
}
=> ์ปจํธ๋กค๋ฌ ์์ ๋ณธ
โถ ๊ฐ์ธ ๊ณต๋ถ
โ ๊ธฐ์ ๋ ๊ฐ์ ์ ๋ฆฌ โ
1. ์ ์ด์ ์ญ์
2. ์คํ๋ง IoC ์ปจํ ์ด๋
IOC ๊ฐ ํ์ ์ ์ฐพ์์ bean์ ์ฃผ์ ํ๋ค.
⇒ ์์กด์ฑ ์ฃผ์ ์ bean๋ผ๋ฆฌ๋ง ๊ฐ๋ฅํ๋ค. ๋ฑ๋ก๋ ๋๋ค๋ง ๊ฐ๋ฅํจ!
3. ์คํ๋ง ๋น(Bean)
4. ์์กด์ฑ ์ฃผ์ (Dependency Injection)
⇒ Spring Framework Reference์์ ๊ถ์ฅํ๋ ๋ฐฉ๋ฒ์ ์์ฑ์ ์ฃผ์ !
⇒ ์์ฑ์ ์ฃผ์ ์ ๋ฌธ์ : ์ํ ์ฐธ์กฐ( a→ b →c ์ฐธ์กฐ....) → ์ด ๊ฒฝ์ฐ๋ Setter or ํ๋ ์ธ์ ์
5. ์คํ๋ง AOP
6. ํ๋ก์ ํจํด
์คํ๋ง์ ๋น ๋ฑ๋ก ์ฌ๋ถ์ ์๊ด์์ด ์๋์ผ๋ก ํ๋ก์ ํจํด์ด ์ ์ฉ๋๋ค.
๋ฅํ ๋งค์ปค๋์ฆ์ ํ ๋น์ ์คํ๋ง3 ์ถ์ฒ!
โถ ์์ ๋ด์ฉ
Spring MVC
ServletContext.xml
component-scan
- Spring Annotation์ ์ฌ์ฉํ ํด๋์ค๊ฐ ์์ฑ๋ ํจํค์ง๋ฅผ ์ค์ ํ๊ธฐ ์ํ ์๋ฆฌ๋จผํธ
- ⇒ ํจํค์ง์ ์์ฑ๋ ํด๋์ค์ ์ด๋ ธํ ์ด์ ์ Spring Container๊ฐ ์ฒ๋ฆฌ
- base-package ์์ฑ : ํจํค์ง ๊ฒฝ๋ก๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ค์
Annotation
@Controller
- ํด๋ผ์ด์ธํธ์ ์์ฒญ์ ์ฒ๋ฆฌํ๋ Controller ํด๋์ค๋ฅผ Spring Bean์ผ๋ก ๋ฑ๋กํ๊ธฐ ์ํ ์ด๋ ธํ ์ด์
- ⇒ ํด๋์ค๋ช ์ด beanName์ผ๋ก ๋ฑ๋ก๋๋ฉฐ value ์์ฑ์ ์ด์ฉํ์ฌ beanName ๋ณ๊ฒฝ ๊ฐ๋ฅ
- ⇒ Controller ์ธํฐํ์ด์ค๋ฅผ ์์๋ฐ์ง ์์๋ Controller ํด๋์ค๋ก ์์ฑ ๊ฐ๋ฅ
- ⇒ ํด๋ผ์ด์ธํธ์ ์์ฒญ์ ์ฒ๋ฆฌํ๋ ๋ค์์ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ ์์ฑ ๊ฐ๋ฅ - @RequestMappint ์ด๋ ธํ ์ด์ ์ฌ์ฉ
@RequestMapping
- ํด๋ผ์ด์ธํธ์ ์์ฒญ์ ๋ํ ์ฒ๋ฆฌ ๋ฉ์๋๋ฅผ ์ค์ ํ๊ธฐ ์ํ ์ด๋ ธํ ์ด์
- ⇒ @GetMapping, @PostMapping, @PutMapping, @DeleteMapping ๋ฑ์ ์ด๋ ธํ ์ด์ ์ฌ์ฉ ๊ฐ๋ฅ
- value ์์ฑ : ํด๋ผ์ด์ธํธ์ ์์ฒญ์ ๋ณด(URL)์ ์์ฑ๊ฐ์ผ๋ก ์ค์
- ⇒ ํด๋ผ์ด์ธํธ ์์ฒญ ์ ๋ณด์ ์ํด Front Controller(Dispatcher Servlet)๊ฐ Controller ํด๋์ค์ ์์ฒญ
- ⇒ ๋ค๋ฅธ ์์ฑ์ด ์๋ ๊ฒฝ์ฐ ์์ฑ๊ฐ๋ง ์ค์ ๊ฐ๋ฅ
- ⇒ ๋ค๋ฅธ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๊ฐ์ ์ด๋ฆ์ ์์ฒญ ์ ๋ณด๊ฐ ์ค์ ๋ ๊ฒฝ์ฐ WAS ์คํ ์ ์๋ฌ ๋ฐ์ - ์ค๋ณต ๊ธ์ง
- method ์์ฑ : ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋๋ฅผ ํธ์ถํ๊ธฐ ์ํ ํด๋ผ์ด์ธํธ ์์ฒญ๋ฐฉ์์ ์์ฑ๊ฐ์ผ๋ก ์ค์
- ⇒ RequestMethod ์๋ฃํ (Enum)์ ์์๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ค์
- ์์ฒญ ๋ฐฉ์์ ๋ฐ๋ผ @GetMapping, @PostMapping ์ด๋ ธํ ์ด์ ์ฌ์ฉํ์ฌ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ ์ค์ ๊ฐ๋ฅ
@RequestMapping ์ด๋ ธํ ์ด์ ์ ์์ฒญ URL ์ฃผ์๊ฐ ๊ฐ์ ๊ฒฝ์ฐ ํด๋ผ์ด์ธํธ์ ์์ฒญ ๋ฐฉ์์ผ๋ก ๊ตฌ๋ถํ์ฌ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ ํธ์ถ ๊ฐ๋ฅ (get, post...)
- ์์ฒญ url์ ๊ฐ๊ฒ ํ๋ฉด ์๋ฌ ์ฒ๋ฆฌ ํ ๋ ํธํจ
- ์์ฒญ ๋ฐฉ์ ์ ํจ์ฑ ๊ฒ์ฌ๋ ํ์ ์์
์ปจํธ๋กค๋ฌ๋ฅผ ์์ ํ๋ฉด ์๋ฒ ๋ฆฌ์คํํธ ํ ์๋ฌ ์ ๋ฌด ํ์ธ
@ModelAttribute
- @ModelAttribute ์ด๋ ธํ ์ด์ ์ ๋ฉ์๋์ ์ ์ธํ ๊ฒฝ์ฐ ๋ฉ์๋ ๋ฐํ๊ฐ(๊ฐ์ฒด)์ ํ์ฌ Controller ํด๋์ค์ ์ ์ธ๋ ๋ชจ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ทฐํ์ด์ง์๊ฒ ์ฌ์ฉ๋๋๋ก ์์ฑ๊ฐ์ ์ ๊ณตํ๋ ์ด๋ ธํ ์ด์
- value(name) ์์ฑ : ๋ทฐํ์ด์ง์์ ๋ฐํ๊ฐ์ ์ฌ์ฉํ๊ธฐ ์ํ ์์ฑ๋ช ์ ์์ฑ๊ฐ์ผ๋ก ์ค์
- ⇒ ๋ค๋ฅธ ์์ฑ์ด ์๋ ๊ฒฝ์ฐ ์์ฑ๊ฐ๋ง ์ค์ ๊ฐ๋ฅ
@RequestParam
- ์ ๋ฌ๊ฐ์ ๋งค๊ฐ๋ณ์์ ์ ์ฅํ๊ธฐ ์ํ ์ด๋ ธํ ์ด์
- ⇒ ๋งค๊ฐ๋ณ์์ ์ด๋ฆ๊ณผ ๊ฐ์ ์ด๋ฆ์ ์ ๋ฌ๊ฐ์ด ์๋ ๊ฒฝ์ฐ 400 ์๋ฌ ๋ฐ์
- ⇒ ๋งค๊ฐ๋ณ์์ ๋ฐ๋์ ์ ๋ฌ๊ฐ์ด ์ ์ฅ๋๋๋ก ์ค์ ํ๊ธฐ ์ํด ์ฌ์ฉํ๋ ์ด๋ ธํ ์ด์
- value ์์ฑ : ์ ๋ฌ๊ฐ์ ์ด๋ฆ์ ์ง์ ํ์ฌ ๋งค๊ฐ๋ณ์์ ์ ๋ฌ๊ฐ ์ ์ฅ ๊ฐ๋ฅ
- ⇒ ๋ค๋ฅธ ์์ฑ์ด ์๋ ๊ฒฝ์ฐ ์์ฑ๊ฐ๋ง ์ค์ ๊ฐ๋ฅ
- required ์์ฑ : false ๋๋ true ์ค ํ๋๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ค์
- ⇒ false : ์ ๋ฌ๊ฐ ๋ฏธํ์, true : ์ ๋ฌ๊ฐ ํ์ - ๊ธฐ๋ณธ
- defaultValue ์์ฑ : ์ ๋ฌ๊ฐ์ ์ด๋ฆ์ด ๋ค๋ฅด๊ฑฐ๋ ์ ๋ฌ๊ฐ์ด ์๋ ๊ฒฝ์ฐ ๋งค๊ฐ๋ณ์์ ์ ์ฅ๋๋ ๊ธฐ๋ณธ ๊ฐ์ ์์ฑ๊ฐ์ผ๋ก ์ค์ - ํ์ด์ง ์ฒ๋ฆฌ ์ ๊ธฐ๋ณธ ํ์ด์ง ๊ฐ!
@RequestMapping(value = "/param", method = RequestMethod.POST)
public String form(@RequestParam(value = "username", defaultValue = "์๊บฝ์ ") String name, Model model) {
model.addAttribute("name", name);
return "param_display";
}
Controller
์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์์ Front Controller(DispatcherServlet)์๊ฒ ViewName์ ์ ๊ณตํ๋ ๋ฐฉ๋ฒ
- ⇒ Front Controller๋ ์ ๊ณต๋ฐ์ ViewName์ ViewResolver ๊ฐ์ฒด์๊ฒ ์ ๋ฌํ์ฌ JSP ํ์ผ๊ฒฝ๋ก๋ฅผ ๋ฐํ๋ฐ์ ํฌ์๋ ์ด๋ํ์ฌ ์๋ต ์ฒ๋ฆฌ
- ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ฐํํ์ void ์๋ฃํ์ผ๋ก ์์ฑํ๋ฉด ๋ฉ์๋๋ช ์ ViewName์ผ๋ก ์ ๊ณต
- ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ฐํํ์ String ํด๋์ค๋ก ์์ฑํ๋ฉด ๋ฐํ๊ฐ(๋ฌธ์์ด)์ ViewName์ผ๋ก ์ ๊ณต → ๋ณดํธ์ ์ผ๋ก ๋ง์ด ์ฌ์ฉ
- ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ฐํํ์ ModelAndView ํด๋์ค๋ก ์์ฑํ๋ฉด ๋ฐํ๋๋ ModelAndView ๊ฐ์ฒด๋ก ViewName์ ์ ์ฅํ์ฌ ์ ๊ณต
์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ์ฒ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋ทฐํ์ด์ง(JSP)์๊ฒ ์ ๊ณตํ๋ ๋ฐฉ๋ฒ
- ModelAndView ๊ฐ์ฒด์ ์ฒ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅํ์ฌ ์ ๊ณต
- ⇒ ๋ทฐํ์ด์ง(JSP)์์ ์ฌ์ฉํ ์ ์๋๋ก ์ฒ๋ฆฌ๊ฒฐ๊ณผ๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅํ๋ ๋ฉ์๋ - RequestScope
- ModelAndView.addObject(String attributeName, @Nullable Object attributeValue)
- HttpServletRequest ๊ฐ์ฒด์ ์ฒ๋ฆฌ๊ฒฐ๊ณผ๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅํ์ฌ ์ ๊ณต
- => ๋ทฐํ์ด์ง(JSP)์์ ์ฒ๋ฆฌ๊ฒฐ๊ณผ๋ฅผ ์ฌ์ฉํ ์ ์๋๋ก HttpServletRequest ๊ฐ์ฒด์ ์์ฑ๊ฐ์ ์ ์ฅํ๋ ๋ฉ์๋
- HttpServletRequest.setAttribute(String attributeName, Object attributeValue)
- Model ๊ฐ์ฒด์ ์ฒ๋ฆฌ๊ฒฐ๊ณผ๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅํ์ฌ ์ ๊ณต
- Model.addAttribute(String attributeName, Object attributeValue)
- => ๋ทฐํ์ด์ง(JSP)์์ ์ฒ๋ฆฌ๊ฒฐ๊ณผ๋ฅผ ์ฌ์ฉํ ์ ์๋๋ก Model ๊ฐ์ฒด์ ์์ฑ๊ฐ์ ์ ์ฅํ๋ ๋ฉ์๋
- Model : ์ฒ๋ฆฌ๊ฒฐ๊ณผ๋ฅผ ์์ฑ๊ฐ์ผ๋ฌ ์ ์ฅํ๊ธฐ ์ํ ๊ฐ์ฒด
์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋งค๊ฐ๋ณ์๋ฅผ ์์ฑํ๋ฉด Spring Container๋ก๋ถํฐ ํ์ํ Spring Bean ๊ฐ์ฒด๋ฅผ ์ ๊ณต๋ฐ์ ๋งค๊ฐ๋ณ์์ ์๋ ์ ์ฅํ์ฌ ์ ๊ณต
Redirect Controller
ํฌ์๋ ์ด๋
- ์๋ฒ ์ธก์์ ๋ค๋ฅธ ์นํ๋ก๊ทธ๋จ(JSP)์ผ๋ก ์ค๋ ๋๋ฅผ ์ด๋ํ์ฌ ์๋ต ์ฒ๋ฆฌ
- ⇒ ํด๋ผ์ด์ธํธ์ ์์ฒญ URL ์ฃผ์ ๋ฏธ๋ณ๊ฒฝ, Request Scope๋ก ์ ๊ณต๋๋ ๊ฐ์ฒด ์ฌ์ฉ ๊ฐ๋ฅ
๋ฐํ๋๋ ViewName ์์ redirect ์ ๋์ฌ(nameSpace)๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฆฌ๋ค์ด๋ ํธ ์ด๋
⇒ ViewName์ ์ํด ๋ทฐํ์ด์ง(JSP)๋ก ์๋ตํ๋ ๋์ ํด๋ผ์ด์ธํธ์๊ฒ URL ์ฃผ์ ์ ๋ฌ
๋ฆฌ๋ค์ด๋ ํธ ์ด๋
- ํด๋ผ์ด์ธํธ์๊ฒ URL ์ฃผ์๋ฅผ ๋ณ๊ฒฝ, Request Scope๋ก ์ ๊ณต๋๋ ๊ฐ์ฒด ์ฌ์ฉ ๋ถ๊ฐ๋ฅ
RedirectAttributes
- ๋ฆฌ๋ค์ด๋ ํธ ์ด๋์ ์ํด ํธ์ถ๋๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ทฐํ์ด์ง์๊ฒ ์์ฑ๊ฐ์ ์ ์ฅํ์ฌ ์ ๊ณตํ๊ธฐ ์ํ ๊ฐ์ฒด
- ⇒ ๋ค์ด๋ ํธ ์ด๋์ ์ํด ํธ์ถ๋๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ทฐํ์ด์ง์๊ฒ ์์ฑ๊ฐ์ ์ ์ฅํ๋ฉฐ ์ ๊ณตํ๋ ๋ฉ์๋
- RedirectAttributes.addFlashAttribute(String attributeName, Object attributeValue)
Method Controller
HttpServletRequest.setCharacterEncoding(String encoding)
- POST ๋ฐฉ์์ผ๋ก ์์ฒญํ์ฌ ์ ๋ฌ๋ ๊ฐ์ ๋ํ ์บ๋ฆญํฐ์ ์ ๋ณ๊ฒฝํ๋ ๋ฉ์๋ - UnSupportedException ๋ฐ์ : ์์ธ ์ฒ๋ฆฌ
Param Controller
@RequestMapping(value = "/param", method = RequestMethod.POST)
public String form(String name, Model model) {
model.addAttribute("name", name);
return "param_display";
}
์ ๋ฌ๊ฐ์ ์ด๋ฆ๊ณผ ๊ฐ์ ์ด๋ฆ์ String ์๋ฃํ์ ๋งค๊ฐ๋ณ์๋ฅผ ์ ์ธํ๋ฉด Front Controller์ ์ํด ์ ๋ฌ๊ฐ์ด ์๋์ผ๋ก ๋งค๊ฐ๋ณ์์ ์ ์ฅ๋์ด ์ ๊ณต
⇒ web.xml ํ์ผ์์ EncodingFilter๋ฅผ ์ฌ์ฉํ์ฌ ์ ๋ฌ๊ฐ์ ๋ํ ์บ๋ฆญํฐ์ ์ค์ ๊ฐ๋ฅ
- ์ ๋ฌ๊ฐ์ ์ด๋ฆ๊ณผ ๋งค๊ฐ๋ณ์์ ์ด๋ฆ์ด ๋ค๋ฅธ ๊ฒฝ์ฐ ๋งค๊ฐ๋ณ์์๋ NULL ์ ์ฅ
- ์ ๋ฌ๊ฐ์ ๋ํ ์บ๋ฆญํฐ์ ์ ๋ฏธ๋ฆฌ ๋ณ๊ฒฝํ๊ธฐ ์ํด web.xml ํ์ผ์์ CharacterEncodingFilter ํด๋์ค๋ฅผ ํํฐ๋ก ๋ฑ๋กํด์ผ๋ง ์ ์์ ์ธ ์ ๋ฌ ๊ฐ์ด ๋งค๊ฐ๋ณ์์ ์ ์ฅ
web.xml
filter
- ํํฐ ํด๋์ค๋ฅผ ํํฐ๋ก ๋ฑ๋กํ๊ธฐ ์ํ ์๋ฆฌ๋จผํธ
Filter ํด๋์ค
- Filter ์ธํฐํ์ด์ค๋ฅผ ์์๋ฐ์ ์์ฑ๋ ์์ํด๋์ค
- ⇒ ์นํ๋ก๊ทธ๋จ ์คํ ์ ๋๋ ํ์ ๋์๋ ๋ช ๋ น์ ์ ๊ณตํ๋ ํด๋์ค
CharacterEncodingFilter
- Spring Framework์์ ์ ๊ณตํ๋ ํํฐ ํด๋์ค๋ก ์์ฒญ ์ฒ๋ฆฌ ์ ๋ฆฌํ์คํธ ๋ฉ์์ง์ ๋ฐ๋(Body)์ ์ ์ฅ๋์ด ์ ๋ฌ๋๋ ๊ฐ์ ์บ๋ฆญํฐ์ ์ ๋ณ๊ฒฝํ๋ ๊ธฐ๋ฅ ์ ๊ณต
- ⇒ encoding ์ด๋ฆ์ผ๋ก ์บ๋ฆญํฐ์ ์ ์ธ์ฝ๋ฉ ๊ฐ์ ๋ฐ๋์ ์ ๋ฌ
filter-mapping
- ํํฐ๊ฐ ์ ์ฉ๋๊ธฐ ์ํ ํด๋ผ์ด์ธํธ ์์ฒญ URL ์ฃผ์์ ํจํด์ ์ค์ ํ๋ ์๋ฆฌ๋จผํธ
'Legacy' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
2022.03.17์ ๊ธฐ๋ก (2) | 2022.03.17 |
---|---|
2022.03.16์ ๊ธฐ๋ก (0) | 2022.03.16 |
2022.03.14์ ๊ธฐ๋ก (0) | 2022.03.14 |
2022.03.11~03.13์ ๊ธฐ๋ก (2) | 2022.03.12 |
2022.03.08~03.10 ์ ๊ธฐ๋ก (0) | 2022.03.09 |