>>> controller
package com.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class SumController { //POJO형식 -> 순수한 자기만의 클래스 (extends implement 모두 안해줌)
//http://localhost:9090/Chapter06_1/input.do
// @RequestMapping(value="/input.do", method = RequestMethod.GET) // get방식
// public ModelAndView input() {
// ModelAndView mav = new ModelAndView();
// mav.setViewName("/sum/input");
// return mav;
// }
//리턴타입이 String이면 문자열이아니라 뷰이름으로 사용된다.
//뷰이름이 아니라 실제 문자열로 리턴하고 싶을때는 @ResponseBody를 사용함
@RequestMapping(value="/input.do", method = RequestMethod.GET) // get방식
public String input() {
return "/sum/input";
}
// @RequestMapping(value="/result.do", method = RequestMethod.GET) // get방식
// public ModelAndView result() {
// ModelAndView mav = new ModelAndView();
// mav.setViewName("/sum/result");
// return mav;
// }
@RequestMapping(value="/result.do", method = RequestMethod.GET) // get방식
public ModelAndView result(@RequestParam int x, int y) {
ModelAndView mav = new ModelAndView();
mav.addObject("x", x);
mav.addObject("y", y);
mav.setViewName("/sum/result");
return mav;
}
}
>>>> result.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%-- ${param.x } + ${param.y } = ${param.x + param.y} --%>
${x } + ${x } = ${x+y }
</body>
</html>
'JAVA 개발 공부 정보' 카테고리의 다른 글
[java-note] Chapter06_1 콘트롤러 다른 방법 (0) | 2018.02.22 |
---|---|
[java-note] Chapter06_1 x, y없을때 modelandview 간소화처리, ModelMap 처리 (0) | 2018.02.22 |
[java-note] WAC (0) | 2018.02.22 |
자바수업-스프링 스프링설정 (0) | 2018.02.22 |
자바수업-스프링 Chapter02-스프링DI (0) | 2018.02.22 |