nus05035056
@nus05035056
Reviews Written
-
Average Rating
-
Posts
Q&A
session์ model์ ๋ฑ๋กํ์ง ์์๋ ๋๋ ์ด์
ํ์ง ์์๋ ๋๋ค๋ ๊ฒ๋ณด๋จ ์๋ก model.addAttribute์ session.setAttribute์ ์ฐจ์ด์ ์ด ์กด์ฌํฉ๋๋ค. model.addAttribute๋ ์์ฒญ๋น์ด๊ณ session.setAttribute๋ ์ธ์ ๋น์ด๋ผ๋ ์ ์ ๋๋ค.Model์ด๋ ํ ์์ฒญ์ผ๋ก model์ ๊ฐ์ ํ ๋นํ๊ณ ์๋ต์ผ๋ก view๋ฅผ ๋ณด๋ด๋ฉด ๊ทธ view์๋ง ํด๋น model๊ฐ์ ๋ ๋๋ง ํ ์ ์์ต๋๋ค. ๊ทธ ํ ์์ฒญ์ ์ฒ๋ฆฌํ ํ ๋ชจ๋ธ์ด ์ญ์ ๋๊ณ ๋ค์ ์์ฒญ์ ๋ํ ์๋ก์ด ๋ชจ๋ธ์ด ์์ฑ๋ฉ๋๋ค.Session๋ก๊ทธ์ธ ๊ฐ์ ๊ฒฝ์ฐ๋ฅผ ์์๋ก ๋ค ์ ์๋๋ฐ ๋ก๊ทธ์ธ์ด ๋ ์์ด๋ ๊ฐ์ ๊ฒฝ์ฐ๋ ํ์ ์์ฒญ์ด ๋ค์ด์์ ์นํ์ด์ง์์ ๊ทธ๋๋ก ๋ก๊ทธ์ธ์ ๋ณด๊ฐ ์์ด์ผ ๋๊ธฐ ๋๋ฌธ์ session์ ์ฌ์ฉํ๋ ๊ฒ๋๋ค. ๋ง์ฝ ๋ก๊ทธ์ธ์ ํ๋ ํ์ด์ง์์ ํด๋ผ์ด์ธํธ๊ฐ ๋ก๊ทธ์ธ ์์ฒญ์ ํ์ ๋ ๊ด๋ จ์ ๋ณด๋ฅผ model์ ๋ด์์ ๊ฒฝ์ฐ ์ผํ์ฑ์ผ๋ก ์ด๋ ํ view์์๋ง ๊ทธ ์ ๋ณด๋ค์ด ๋ณด์ฌ์ง๊ฒ ์ฃ .ํน์๋ ํ๋ ์๊ฐ์ ๊ฐ๋ตํ ์ฝ๋๋ก ๋ณด์ฌ๋๋ฆฌ๊ฒ ์ต๋๋ค.@GetMapping("/test") public String login() { return "/test"; } @PostMapping("/login") public String postLogin(HttpSession session, @RequestParam String id, Model model) { //Session์ ๋ด๊ธด ๊ฐ session.setAttribute("id", id); //Model์ ๋ด๊ธด ๊ฐ model.addAttribute("id", id); return "/login"; } @GetMapping("/login2") public String postLogin() { return "/login2"; }test.html ID PWD ๋ก๊ทธ์ธ login.html Session์ ๋ด๊ธด ๊ฐ ํ์ธ [[${session.id}]]๋ ์๋ ํ์ธ์ Model์ ๋ด๊ธด ๊ฐ ํ์ธ [[${id}]]๋ ์๋ ํ์ธ์ login2.html Session์ ๋ด๊ธด ๊ฐ ์ฌํ์ธ [[${session.id}]]๋ ์๋ ํ์ธ์ Model์ ๋ด๊ธด ๊ฐ ์ฌํ์ธ [[${id}]]๋ ์๋ ํ์ธ์
- 1
- 1
- 2K
Q&A
thymeleaf ์ ์ฉ์ด ์๋ฉ๋๋ค.
์ง์ ๋ค์ด ๋ฐ์ ํ์ธํด๋ดค๋๋ฐ item๋๋ฉ์ธ๊ฐ์ฒด๋ฅผ model์ ๋ด์ผ์ค ๋ ํค ๊ฐ์ item์ผ๋ก ํ์ จ๋๋ฐ items.html์ ์ฝ๋์์ modelํค ๊ฐ์ ${items} ์ผ๋ก ํ์ จ๋ค์ item์ผ๋ก ๋ฐ๊พธ์๋ฉด ๋ฉ๋๋ค. ๊ธฐ์กด์ฝ๋ ์์ ๋ ์ฝ๋
- 0
- 2
- 2.8K
Q&A
์์ ์๋ฃ ์ ๋ชฉ์ด ์๊พธ ๊นจ์ง๋๋ฐ์(window)
์ง๊ธ ๋ณด์ด๋ ํ๋ฉด์ ์ ์๋จ ์นดํ ๊ณ ๋ฆฌ ์ค ๋ณด๊ธฐ๋ฅผ ์ ํํ์ ํ ์ธ์ด๋ณํ์ ๋์ ํ ํ๊ตญ์ด ํน์ ์ ๋์ฝ๋๋ก ๋ณํํด ๋ณด์ธ์.๋งํฌ ํ๋ ๋จ๊ฒจ๋๊ฒ ์ต๋๋ค.https://www.urbanbrush.net/%ED%95%9C%EA%B8%80%EA%B9%A8%EC%A7%80%EB%8A%94%ED%98%84%EC%83%81/
- 0
- 2
- 470
Q&A
HTTP ์๋ต ๋ฐ์ดํฐ - json
๊ฐ์์ฒ๋ผ response.getWriter().write(result); ์ด๋ ๊ฒ ์ถ๋ ฅ์ ํ์ จ๋ค๋ฉด response.setCharacterEncoding("utf-8");ํน์//response.setCharacterEncoding("utf-8");์ ๋ฐ๋ผ ์ธ์ฝ๋ฉ์ด ์ ์ฉ๋ ์๋ ์ ๋ ์๋ ์์ต๋๋ค.๋ง์ฝ ์ธ์ฝ๋ฉํ์์ ์ ์ ์ผ์ จ๋ค๋ฉด ํฌ๋กฌ ๋ธ๋ผ์ฐ์ ๊ธฐ์ค์ผ๋กContent-type์ด application/json;charset=ISO-8859-1 ์ธ์ฝ๋ฉํ์์ ์ ์ ๊ณ utf-8 ํ์์ผ๋ก ํ๊ณ ์ถ๋ค๋ฉด ๊น์ํ๋์ด ๋ง์ํ์ ๋๋ก getWriter() ๋์ getOutputStream ๋ฉ์๋๋ฅผ ์ด์ฉ ํ์๋ฉด ๋ฉ๋๋ค. private ObjectMapper objectMapper = new ObjectMapper(); @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); //response.setCharacterEncoding("utf-8"); HelloData helloData = new HelloData(); helloData.setUsername("๊น"); helloData.setAge(20); String result = objectMapper.writeValueAsString(helloData); OutputStream os = response.getOutputStream(); PrintStream out = new PrintStream(os, true); out.println(result);์ด๋ ๊ฒ ํด๋ณด์๋ฉด ์ธ์ฝ๋ฉํ์ ์ ์ ์ด๋ ์ ์ฉ์ด ๋ ๊ฒ๋๋ค.
- 3
- 1
- 858
Q&A
gradle.build ์ค๋ฅ..
2๋ฒ์งธ ๋ผ์ธ์ version์ 2.7.7 ๋ก ๋ฐ๊ฟ๋ณด์๋ฉด bulid์๋ก๊ณ ์นจ ํด๋ณด์ธ์ ์ต์ ๋ฒ์ ์ผ๋ก ํ๋ฉด ๋๊ฐ์ดbulid error ๋๋๋ผ๊ตฌ์
- 0
- 2
- 3.7K




