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

8/20

by woohyun22 2018. 8. 20.
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
<?xml version="1.0" encoding="UTF-8"?>
 
<beans xmlns ="http://www.springframework.org/schema/beans"
xmlns:context ="http://www.springframework.org/schema/context"
xmlns:mvc ="http://www.springframework.org/schema/mvc"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
 
<context:component-scan base-package="Pack01" />
<context:component-scan base-package="Pack02" />
<!-- 추가하면 01,02를 다돌면서 찾는다. -->
<mvc:annotation-driven/>
<mvc:default-servlet-handler/>
 
<mvc:view-resolvers>
<mvc:jsp prefix="/WEB-INF/Views/"/>
<!-- 얘는 views안에다가 폴더를 만들어서 써야된다. 위같은 방식이 안된다. -->
</mvc:view-resolvers>
<mvc:view-controller path= "/t13" view-name="BananaView"/>
<!-- 13이 나오면 바나나뷰로 -->
</beans>
 
cs



tiger


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
package Pack01;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.LinkedList;
 
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("t24")
    String func24(Model model) {
        System.out.println("24번째");
        Coffee coffee = new Coffee("홍길동",400);
        model.addAttribute("Coffee",coffee);
        return "LionView";
    }
    @RequestMapping("t25")
    String func25(Model model) {
        Coffee[] ar = new Coffee[4];
        ar[0]=new Coffee("김유신",100);
        ar[1]=new Coffee("김유신1",200);
        ar[2]=new Coffee("김유신2",300);
        ar[3]=new Coffee("김유신3",400);
        model.addAttribute("ar",ar);
        return "LionView";
    }
    @RequestMapping("t26")
    String func26(Model model) {
        LinkedList<Coffee> li = new LinkedList<>();
        li.add(new Coffee("김유신",100));
        li.add(new Coffee("김유신",100));
        li.add(new Coffee("김유신",100));
        li.add(new Coffee("김유신",100));
        model.addAttribute("li",li);
        return "LionView";
    }
    @RequestMapping("t27")
    String func27(Model model ,String name, int age,String home, int salary) {
        model.addAttribute("name", name);
        model.addAttribute("age", age);
        model.addAttribute("home", home);
        model.addAttribute("salary", salary);
         try {
                //1단계 : class 확인
                //현재 찾고 싶은 클래스를 찾아준다.
                String driver = "oracle.jdbc.driver.OracleDriver";
                System.out.println(Class.forName(driver));
                //2단계 : 로그인
                Connection con = null;
                String dburl = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
                String username = "jwh";
                String password = "1";
                con = DriverManager.getConnection(dburl, username, password);
                //3단계: 쿼리문 작성 및 컴파일
                PreparedStatement ps = null;
                //String sql="INSERT into banana values('개나리',25,1000,'하회마을')";
     
                String sql = String.format("insert into banana values('%s',%d,%d,'%s')", name, age, home,salary);
                System.out.println(sql);
                ps = con.prepareStatement(sql);
                //4단계: 실행
                ps.executeUpdate(); //f5번 누른것과 같다.
                //5단계: 접속 종료
                ps.close();
            } catch (Exception e) {
     
                // TODO: handle exception
                e.printStackTrace();
            }
         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
<%@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>
    여긴 사자
    
    ${coffee.nickname}
    ${coffee.salary}
    
    <%-- <c:forEach var="ii" items="${ar}">
    ${ii.nickname}
    ${ii.salary}
    </c:forEach>  --%>
    
    <c:forEach var="ii" items="${li}">
    ${ii.nickname}
    ${ii.salary}
    </c:forEach>
</body>
</html>
cs


index


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<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="t24">링크24</a>
     <a href="t25">링크25</a>
     <a href="t26">링크26</a>
     <form action="t27">
    이름 : <input type = "text" name = "nickname" value = "jeong" ><br>
    나이 : <input type = "number" name = "age" value = 25><br>
    고향: <input type = "text" name = "home" value = "busan" ><br>
    연봉 : <input type = "number" name = "salary" value = 3000><br>
    <input type="submit"><br>
</body>
</html>
cs



728x90

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

jsp 로그인창 + session활용  (0) 2018.08.22
8/18 복습  (0) 2018.08.21
kk  (0) 2018.08.20
8/17 jsp  (0) 2018.08.17
xml  (0) 2018.08.13

댓글