<!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=EUC-KR">
<title>Start</title>
</head>
<body>
<form action="HelloWorld.do" method="post">
전솔할 데이터 :
<input type="text" name="hello">
<input type="submit" value="send">
</form>
</body>
</html>
HelloWorld.do
HelloWorld.java
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloWorld
{
@RequestMapping("/HelloWorld")
public ModelAndView printHello(String hello)
{
//model과 view를 동시에 지정 가능한 객체 선언
ModelAndView mav = new ModelAndView();
String data = "Hello, "+hello+"!";
//결과를 보여줄 jsp파일명을 설정
mav.setViewName("ResultHelloWorld");
//jsp로 떠널길 데이터를 부착
mav.addObject("hellodata",data);
return mav;
}
}
ResultHelloWorld.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>result</title>
</head>
<body>
<center>
<h2>result</h2>
${hellodata}
</center>
</body>
</html>
result)
댓글 없음:
댓글 쓰기