본문 바로가기
IT/SPRING

[Spring] 값 보내기

by dya0 2019. 6. 26.

정상적으로 작동 시키는 코드

1
2
3
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:forward page="view/LoginForm8.jsp"></jsp:forward>
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

index8.jsp

LoginForm8.jsp

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
31
32
33
34
35
36
37
38
39
40
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
 
<head>
<meta charset="UTF-8">
<script
<title>로그인 입력</title>
<style>
form {
    margin: auto;
    text-align: center
}
 
tr, td {
    text-align: center
}
</style>
</head>
 
<body>
    <form action="login_ok8.do" method="post" name="loginform8">
        <table>
            <tr>
 
                <td>나이</td>
                <td><input tpye="text" name="age"></td>
            </tr>
            <tr>
                <td colspan="2" style="background: lightgreen"><input
                    type="submit" value="로그인"></td>
            </tr>
 
        </table>
 
    </form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

Controller.java

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
 
import org.springframework.stereotype.Controller;
 
@Controller
public class RController {
    /*
      1. 정상실행 
      Command 객체에 없는 파라미터를 처리하는 방법
      
      @RequestParam(value="age") int age 
        파라미터 age를 정수형 변수 age에 저장하라는 의미이다. 
      String으로 넘어오는 파라미터의 값을 변수형에 맞추어 캐스팅한다.
     */
 
    @RequestMapping(value = "/login_ok8.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String login_ok8(@RequestParam(value ="age")int age,Model model) throws Exception {
//model 값만 저장한다. view 페이지에서 모델 객체에 담아있는거 사용가능
        model.addAttribute("age",age);
        return "list8";
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

 

list8.jsp

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
31
32
33
34
35
36
37
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
 
<head>
<meta charset="UTF-8">
<script
<title>로그인 입력</title>
<style>
form {
    margin: auto;
    text-align: center
}
 
tr, td {
    text-align: center
}
</style>
</head>
 
<body>
    <form action="login_ok8.do" method="post" name="loginform8">
        <table>
            <tr>
 
                <td>나이</td>
                <td>${age}</td>
            </tr>
 
 
        </table>
 
    </form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

 

RController 수정

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
31
32
33
34
35
36
 
import org.springframework.stereotype.Controller;
 
@Controller
public class RController {
    /*
      1. 정상실행 
      Command 객체에 없는 파라미터를 처리하는 방법
      
      @RequestParam(value="age") int age 
        파라미터 age를 정수형 변수 age에 저장하라는 의미이다. 
      String으로 넘어오는 파라미터의 값을 변수형에 맞추어 캐스팅한다.
     */
 
    @RequestMapping(value = "/login_ok8.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String login_ok8(@RequestParam(value ="age")int age,Model model) throws Exception {
//model 값만 저장한다. view 페이지에서 모델 객체에 담아있는거 사용가능
        model.addAttribute("age",age);
        return "list8";
    }
    
 
    @RequestMapping(value = "/login_ok9.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String login_ok9(@RequestParam(value ="age2")int age,Model model) throws Exception {
//model 값만 저장한다. view 페이지에서 모델 객체에 담아있는거 사용가능
        model.addAttribute("age",age);
        return "list8";
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

value2인 경우 에러

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
31
32
33
34
35
36
 
import org.springframework.stereotype.Controller;
 
@Controller
public class RController {
    /*
      1. 정상실행 
      Command 객체에 없는 파라미터를 처리하는 방법
      
      @RequestParam(value="age") int age 
        파라미터 age를 정수형 변수 age에 저장하라는 의미이다. 
      String으로 넘어오는 파라미터의 값을 변수형에 맞추어 캐스팅한다.
     */
 
    @RequestMapping(value = "/login_ok8.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String login_ok8(@RequestParam(value ="age")int age,Model model) throws Exception {
//model 값만 저장한다. view 페이지에서 모델 객체에 담아있는거 사용가능
        model.addAttribute("age",age);
        return "list8";
    }
    
 
    @RequestMapping(value = "/login_ok9.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String login_ok9(@RequestParam(value ="age2", required=false)int age,Model model) throws Exception {
//model 값만 저장한다. view 페이지에서 모델 객체에 담아있는거 사용가능
        model.addAttribute("age",age);
        return "list8";
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

400오류 수정 후 500에러 발생 

 

1
2
3
4
5
6
7
    @RequestMapping(value = "/login_ok10.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String login_ok10(@RequestParam(value = "age2", defaultValue = "10", required = falseint age, Model model)
            throws Exception {
//model 값만 저장한다. view 페이지에서 모델 객체에 담아있는거 사용가능
        model.addAttribute("age", age);
        return "list8";
    }
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

1
2
3
4
5
6
7
    @RequestMapping(value = "/login_ok11.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String login_ok11(int age, Model model)
            throws Exception {
//model 값만 저장한다. view 페이지에서 모델 객체에 담아있는거 사용가능
        model.addAttribute("age", age);
        return "list8";
    }
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

'IT > SPRING' 카테고리의 다른 글

AOP 용어  (0) 2019.07.04
[Spring] 스프링 계층 구조  (0) 2019.06.26
[SPRING]Spring MVC web.xml에 filter 기능 추가  (0) 2019.06.21
[SPRING] 컨테이너 정리  (0) 2019.06.21
[Spring] 시작하기  (0) 2019.06.20