티스토리 뷰

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    @RequestMapping(value = "/html/test01", method = RequestMethod.POST)
    public String test01post(@RequestParam(value = "email", defaultValue = "0", required = trueString email,
            @RequestParam(value = "password", defaultValue = "0", required = trueString password, Model model,
            HttpSession ses) {
 
        System.out.printf("id %s \n", email);
        System.out.printf("password %s \n", password);
 
        model.addAttribute("result", password);
 
        ses.setAttribute("login", email);
 
        return "./html/test01";
    }
cs


RequestParam은 요청된 파라메타가 없으면 처리해주는 방식이다. 


required : 필수인지 아닌지 선택, 만약 false 라면 defaltValue로 간다.

defaltValue : 기본값. flase인 경우 동작


1
2
3
4
5
6
7
8
    @RequestMapping(value = "/html/test01Model", method = RequestMethod.POST)
    public String test02post(@ModelAttribute("info") users user, HttpSession ses) {
        System.out.printf("ModelAttribute \n");
        System.out.printf("user %s  \n", user);
        ses.setAttribute("login", user.getEmail());
 
        return "./html/test01";
    }
cs


@ModelAttribute 는 받아오는 데이터를 지정한다.

Vo로 지정된 형태인데, info로 model에 저장을 해준다. 그래서 JSP페이지에서는


1
  <p>ModelAttribute result: ${info.email}</p>
cs


을 쓰면 자동을 보인다. 


1
@SessionAttributes("board")
cs


SessionAttributes는 "----"이름으로 된 것은 Session에 자동으로 저장된다. 

여러개를 저장할 땐 SessionAttributes(["data1", "data2"])


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@RequestMapping(value = "/html/test01", method = RequestMethod.POST)
    public String test01post(@RequestParam(value = "email", defaultValue = "0", required = falseString email,
            @RequestParam(value = "password", defaultValue = "0", required = trueString password, Model model,
            HttpSession ses, HttpServletResponse response) {
 
        System.out.printf("id %s \n ", email);
        System.out.printf("password %s \n ", password);
 
        model.addAttribute("result", email);
        //세션저장
        //@SessionAttributes("login") 으로 자동으로 저장할 수 있다. 
        ses.setAttribute("login", email);
        // 세션의 타임아웃 설정 : 1초당으로 계산된다. 
        ses.setMaxInactiveInterval(20*60);
        
        //쿠키로 저장하는 방법
        Cookie cookie = new Cookie("login", email);
        // 쿠키시간 설정
        cookie.setMaxAge(20*60);    
        //마지막에 HttpServletResponse 에 add해줘야 한다.
        response.addCookie(cookie);
        
 
        return "./html/test01";
    }
cs


이런식으로 사용이 가능






공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함