티스토리 뷰
src/main/java > com.care.mvc_ex01 > MyController.java src > main > webapp > WEB-INF > views > member > index.jsp > login.jsp > logout.jsp |
MyController.java
package com.care.mvc_ex01;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MyController {
@RequestMapping(value = "/index")
public String memberIndex() {
return "member/index";
}
@RequestMapping(value = "/login")
public String memberLogin() {
return "member/login";
}
@RequestMapping(value = "/logout")
public String memberLogout() {
return "member/logout";
}
}
servlet-context.xml를 보면
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<context:component-scan base-package="com.care.mvc_ex01"></context:component-scan>
이런 코드가 있습니다.
이 코드는 @Controller가 있는 클래스를 찾아가 실행한다는 의미를 갖고 있습니다.(@를 annotation이라고 합니다)
@Controller를 찾기 위한 경로로는 com.care.mvc_ex01로 지정해주었습니다.
그렇기 때문에 MyController에 @Controller를 달아주고 각 기능들을 호출하기 위해서는 @RequestMapping를 사용합니다.
@RequestMapping(value = "/index")라는 것은 최상위 경로뒤에 index를 붙이면 memberIndex()가 실행이 된다고 생각해주시면 됩니다.
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>index</title>
</head>
<body>
<h2>index페이지 입니다</h2>
</body>
</html>
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>login</title>
</head>
<body>
<h2>로그인 페이지 입니다</h2>
</body>
</html>
logout.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>logout</title>
</head>
<body>
<h2>로그아웃 페이지 입니다</h2>
</body>
</html>
'Spring' 카테고리의 다른 글
스프링_@RequestParam 간단하게 사용해보기 (0) | 2021.05.25 |
---|---|
스프링_Annotation(@RequestMapping,@GetMapping,@PostMapping)을 이용하여 더 짧고 간단하게 get,Post방식으로 보내기 (0) | 2021.05.25 |
스프링_post로 보내기 get으로 보내기 (0) | 2021.05.25 |
스프링_Annotation(@) Autowired, Component사용하기 (0) | 2021.05.25 |
스프링_mv2로 명령어를 지정해 사용해보기/내용 추가 기능 (0) | 2021.05.21 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- jsp
- RequestDispatcher
- Expression
- session
- CLASS
- Margin
- forward
- link href
- 정보산업처리기사
- request
- Redirect
- div
- 자격증
- Declaration
- NAV
- 정처산기
- application
- span
- 독학
- 실기
- 합격
- dl
- pageContext
- 정처기
- id
- padding
- this.
- getParameter
- scriptlet
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함