국비 49일차_1

강지수·2024년 2월 26일
0

국비교육

목록 보기
85/97

지난 시간 복습


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>modelView2.jsp</h3>

<c:forEach items="${hobbys }" var="hob">
	${hob } ,
</c:forEach>
<br />
<c:forEach items="${hobbys }" var="hob" varStatus="st">
	${hob }<c:if test="${not st.last }">,</c:if>
</c:forEach>
<br />
<c:forEach items="${hobbys }" var="hob" varStatus="st">
	${hob }<c:if test="${not st.last }">,</c:if>
</c:forEach>
<br />
hobbys : ${hobbys } <br />
data : ${data } <br />
</body>
</html>

modelView2.jsp


package com.tech.ex;

import java.util.ArrayList;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/board")
public class MyMapController {
	@RequestMapping("/bview")
	public String bview(Model model) {
		model.addAttribute("id", "aaa");
		return "/board/bview";
	}
	@RequestMapping("/modelAndView/modelView2")
	public ModelAndView modelView2(Model model) {
		ModelAndView mv=new ModelAndView();

		ArrayList<String> list=new ArrayList<String>();
		list.add("movie1");
		list.add("movie2");
		list.add("movie3");
		list.add("movie4");
		list.add("movie5");
		mv.addObject("hobbys",list);
		mv.addObject("data","modelAndView");
		mv.setViewName("/modelAndView/modelView2");
		
		return mv;
	}

}

MyMapController.java



package com.tech.sprjt07;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {
	
	@RequestMapping("/login/loginForm")
	public String loginForm() {
		
		return "/login/loginForm";
	}
	@RequestMapping("/login/loginConfirm")
	public String loginConfirm(HttpServletRequest request, Model model) {
		String id=request.getParameter("id");
		String pw=request.getParameter("pw");
		
		model.addAttribute("id",id);
		model.addAttribute("pw",pw);
		
		request.setAttribute("rid",id);
		request.setAttribute("rpw", pw);
		
		return "/login/loginConfirm";
	}
}

LoginController.java


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>loginForm.jsp</h3>

<form action="./loginConfirm">
	id : <input type="text" id="id" name="id" /> <br />
	pw : <input type="text" id="pw" name="pw" /> <br />
	<input type="submit" value="login" /> <br />
</form>
</body>
</html>

loginForm.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>loginConfirm.jsp</h3>
id : ${id } <br />
pw : ${pw } <br />
<hr />
id : ${ird } <br />
pw : ${rpw } <br />
</body>
</html>

loginConfirm.jsp



	@RequestMapping(method = RequestMethod.POST, value= "board/confirm")
	public String confirm(HttpServletRequest request, Model model) {
		String id=request.getParameter("id");
		String pw=request.getParameter("pw");
		
		model.addAttribute("id", id);
		model.addAttribute("pw", pw);
		
		return "board/confirm";
	}

post 방식으로 받을 때 mapping 하는 방법


package com.tech.model;

public class studentInfo {
	private String id;
	private String pw;
	private String age;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getPw() {
		return pw;
	}
	public void setPw(String pw) {
		this.pw = pw;
	}
	public String getAge() {
		return age;
	}
	public void setAge(String age) {
		this.age = age;
	}
	
}

studentInfo.java


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>studentInfo.jsp</h3>
<h3>결과</h3>
id : ${studentInfo.id } <br />
pw : ${studentInfo.pw } <br />
age : ${studentInfo.age } <br />
</body>
</html>

studentInfo.jsp

	@RequestMapping("board/studentForm")
	public String studentForm() {
		
		
		return "board/studentForm";
	}
	@RequestMapping("board/studentInfo")
	public String studentInfo(@ModelAttribute("") studentInfo studentInfo) {
		
		
		return "board/studentInfo";
	}

Controller.java


데이터 객체 통째로 전달


profile
개발자 준비의 준비준비중..

0개의 댓글