spring봄프레임워크
spring Get,post 으로 test 출력하기.
woody1505
2021. 4. 9. 17:16
HomeHomeController.java
//post 답변
@RequestMapping(value = "/test/po", method = RequestMethod.POST)
public ModelAndView ttt(@RequestParam("id") String id, Model model) {
ModelAndView mav = new ModelAndView();
mav.addObject("id", id);
mav.setViewName("test/t2");
return mav;
}
//get 답변
@RequestMapping(value = "/test/ge", method = RequestMethod.GET)
public String tt(HttpServletRequest request, Model model) {
String id = request.getParameter("id");
model.addAttribute("id", id);
return "test/t2";
}
//질문
@RequestMapping(value = "/test/t1")
public String tttt() {
return "test/t1";
}
<test/t1.jsp>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form method= get action="./ge"><!-- 전송할때는 현재페이지 기준으로 잡히기 때문에 ./t2만 쓴다. -->
student id : </td><input type= text name = id>
<input type = submit value= "get전송" >
</form>
<form method= post action="./po"><!-- 전송할때는 현재페이지 기준으로 잡히기 때문에 ./t2만 쓴다. -->
student id : </td><input type= text name = id>
<input type = submit value= "post전송" >
</form>
</body>
</html>
<test/t2.jsp>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
student id :${id}
</body>
</html>