본문 바로가기
비트 장기/jsp

8/18 mvc

by woohyun22 2018. 8. 18.

for문 


index


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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ page import="java.util.*, java.text.*"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <!-- 이게 있어야 jstl쓸수있음. -->
<head>
<title>메인 페이지</title>
</head>
<body>
        <%=new Date()%><!-- 갱신이 안되고있을때를 확인하기 위해서 -->
        <h2>Hello World</h2>
        <a href = "t1">링크1</a><br>
        <a href = "t3">링크3</a><br>
        <a href = "t4?nickname=apple">링크4</a><br>
        <a href = "t5?nickname=apple&salary=300">링크5</a><br>
        <a href = "t6?nickname=banana&salary=400">링크6</a><br>
        <a href = "t7?nickname=banana&salary=500">링크7</a><br>
        <a href = "t8?nickname=banana&salary=600">링크8</a><br>
        <a href = "t9?nickname=banana&salary=700">링크9</a><br>
        <a href = "t10?nickname=banana&salary=800">링크10</a><br>
        <a href = "t10?nickname=banana&salary=801">링크11</a><br>
        <a href = "t12?nickname=LionView&salary=900">링크12</a><br>
        <a href = "t13">링크13</a><br>
        
        <a href = "t16?nickname=호랑이">링크16</a><br>
        <!-- 한개이상 사용가능 servlet.xml에 넣어주면된다. 
            인수전달을 받고싶을때는 getparmeter만 된다.
            xml을 건드릴떄는 항상 alt f5와 저장해줘야된다.
         -->
    <form action="t17">
    <!-- vlaue = 초기값잡아주기 -->
    이름 : <input type = "text" name = "name" value = "홍길동" ><br>
    월급 : <input type = "number" name = "salary" value = 300><br>
<!-- input type = number 은 숫자만 넣고 싶을때 쓴다. -->
    <input type="submit"><br>
    </form>
    <form action="t18">
    <!-- vlaue = 초기값잡아주기 -->
    이름 : <input type = "text" name = "nickname" value = "hong" ><br>
    월급 : <input type = "number" name = "salary" value = 300><br>
<!-- input type = number 은 숫자만 넣고 싶을때 쓴다. -->
    <input type="submit"><br>
    </form>
    <form action="t19">
    <!-- vlaue = 초기값잡아주기 -->
    이름 : <input type = "text" name = "nickname" value = "hong" ><br>
    월급 : <input type = "number" name = "salary" value = 300><br>
<!-- input type = number 은 숫자만 넣고 싶을때 쓴다. -->
    <input type="submit"><br>
    </form>
     <a href="t23">링크23</a>
</body>
</html>
cs



Tiger.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package Pack01;
import javax.security.auth.message.callback.PrivateKeyCallback.Request;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class Tiger {
    @RequestMapping("t1")
    String func01() {
        System.out.println("들어왔음");
        return "TigerView";
    }
    @RequestMapping("t3")
    String func03() {
        System.out.println("라이언 들어왔음");
        return "LionView";
    }
    /*@RequestMapping("t4")
    String func04(String nickname) {
        //String func04(@RequestParam(value = "nickname") String nickname)
        //String func04(@RequestParam(value = "nickname") String s)
        System.out.println(nickname);
        return "LionView";
    }*/
    @RequestMapping("t4")
    String func04(String nickname) {
        System.out.println(nickname);
        return "LionView";
    }
    /*@RequestMapping("t5")
    String func05(
        @RequestParam(value = "nickname")String nickname,
        @RequestParam(value = "salary")int salary
        ) {
        System.out.println(nickname+salary);
        return "LionView";
    }*/
    @RequestMapping("t5")
    String func05(String nickname, int salary) {
        System.out.println(nickname+salary);
        return "LionView";
    }
    @RequestMapping("t6")
    String func06(Model model,String nickname, int salary) {
        model.addAttribute("k1", "dog");
        model.addAttribute("k2", salary);
        System.out.println(nickname+salary);
        return "LionView";
    }
    @RequestMapping("t7")
    ModelAndView func07(Model model,String nickname,int salary) {
        //s나 n이면 안되고 던졌을떄 그대로 보내줘야된다.
        //modelandview쓸때는 위에도 바꿔줘야된다.
        System.out.println(nickname+salary);
        ModelAndView mv = new ModelAndView("LionView");
        mv.addObject("f1", nickname);
        mv.addObject("f2", salary);
        //return을 lionview로 안가고 다른 방법으로 가기
        return mv;
    }
    /*@RequestMapping("t8")
    ModelAndView func08(Model model,HttpServletRequest hsr) {
        //String s = (String)hsr.getAttribute("nickname");
        //int n = (Integer)hsr.getAttribute("salary");
        //여기서는 getattribue를 쓸수없다
        String s = (String)hsr.getParameter("nickname");
        String n = (String)hsr.getParameter("salary");
        ModelAndView mv = new ModelAndView("LionView");
        System.out.println(s+n);
        mv.addObject("f1", s);
        mv.addObject("f2", n);
        //getparameter는 string바께 안되서 받은 후 직접 바꿔줘야된다.
        return mv;
    }*/
    @RequestMapping("t8")
    String func08(Model model,HttpServletRequest hsr) {
        String s = (String)hsr.getParameter("nickname");
        String n = (String)hsr.getParameter("salary");
        model.addAttribute("f1", s);
        model.addAttribute("f2", n);
        System.out.println(s+n);
        //getparameter는 string바께 안되서 받은 후 직접 바꿔줘야된다.
        return "LionView";
    }
    @RequestMapping("t9")
    String func09() {
        System.out.println("함수9번 들어옴");
        return "LionView";
    }
    @RequestMapping("t10")
    ModelAndView func010(int salary) {
        //던지는 거 model로
        ModelAndView mv;
        if(salary%2==0)
        {    
            mv = new ModelAndView("TigerView");
        }
        else {
            mv = new ModelAndView("LionView");
        }
        return mv;
    }
    @RequestMapping("t11")
    ModelAndView func011(int salary) {
        //던지는 거 model로
        ModelAndView mv;
        if(salary%2==0)
        {    
            mv = new ModelAndView("TigerView");
        }
        else {
            mv = new ModelAndView("LionView");
        }
        return mv;
    }
    @RequestMapping("t12")
    ModelAndView func012(String nickname) {
        //던지는 거 model로
        ModelAndView mv = new ModelAndView("LionView");
        return mv;
    }
    
    @RequestMapping("t16")
    String func16(Model model,HttpServletRequest hsr) {
        String s = (String)hsr.getParameter("nickname");
        model.addAttribute("f1", "호랑이");
        System.out.println(s);
        //getparameter는 string바께 안되서 받은 후 직접 바꿔줘야된다.
        return "LionView";
    }
    @RequestMapping("t17")
    String func17(Model model,String name, int salary) {
        {
            model.addAttribute("f1", name);
            model.addAttribute("f2", salary);
            System.out.println(name+salary);
            return "LionView";
        }
    }
    @RequestMapping("t18")
    String func18(Coffee coffee) {
        {
            System.out.println("18번째");
            System.out.println(coffee.getNickname());
            System.out.println(coffee.getSalary());
            return "LionView";
        }
    }
    @RequestMapping("t19")
    ModelAndView func19(Model model,Coffee coffee) {
        {
            System.out.println("18번째");
            System.out.println(coffee.getNickname());
            System.out.println(coffee.getSalary());
            model.addAttribute(""+coffee);
            ModelAndView mv = new ModelAndView("LionView");
            return mv;
        }
    }
    @RequestMapping("t23")
    String func23(Model model) {
        
            System.out.println("23번째");
            String[] ar = new String[5];
            ar[0]="호랑이0";
            ar[1]="호랑이1";
            ar[2]="호랑이2";
            ar[3]="호랑이3";
            ar[4]="호랑이4";
            model.addAttribute("ar",ar);
            return "LionView";
    }
}
 
cs



LionView


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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<%@page import="Pack01.Coffee"%>
<%@page
    import="javax.security.auth.message.callback.PrivateKeyCallback.Request"%>
<%@page
    import="javax.security.auth.message.callback.PrivateKeyCallback.Request"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
    여긴 사자 홀수
    <%-- <c:forEach var="ii" items="${ar}">
    ${ii}
    <h1>${"ii"}</h1>
    </c:forEach> --%>
     <table border="1">
    <c:forEach var="ii" items="${ar}">
    <tr>
    <td>
    ${ii}
    </td>
    </tr>
    </c:forEach>
    
<!-- 값을 ii로 넣어줄테니 써라 items에 배열 넣어주기 -->
    </table>
    <br>
<%--     <%
        String nickname = (String) request.getAttribute("nickname");
        int salary = (Integer) request.getAttribute("salary");
    %> --%>
    <%-- <h1>${k1}</h1><br>
${k2}<br>
${f1}<br>
${f2}<br> --%>
<%--     ${f1}
    <br> ${f2}
    <%
        Coffee c = (Coffee)request.getAttribute("coffee");
    %>
    <%=c.getNickname() %>
    <%=c.getSalary() %>
    <!-- el -->
    ${coffee.nickname}
    ${coffee.salary}
    
    ${coffee.getNickname()}
    ${coffee.getSalary()} --%>
</body>
</html>
cs


728x90

'비트 장기 > jsp' 카테고리의 다른 글

8/18 복습17일꺼 보충 mvc넘어가는거 알기  (0) 2018.08.19
8/17 jsp 복습  (0) 2018.08.18
8/16 (out,)  (0) 2018.08.16
8/14 복습(count쓰는법? rs.next())  (0) 2018.08.16
8/13 복습  (0) 2018.08.14

댓글