MCPcopy Create free account
hub / github.com/castello/spring_basic / YoilTeller

Class YoilTeller

ch2/YoilTeller.java:12–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import java.util.Calendar;
11
12@Controller
13public class YoilTeller {
14 @RequestMapping("/getYoil") // http://localhost:8080/ch2/getYoil?year=2021&month=10&day=1
15 // public static void main(String[] args) {
16 public void main(HttpServletRequest request, HttpServletResponse response) throws IOException {
17 // 1. 입력
18// String year = args[0];
19// String month = args[1];
20// String day = args[2];
21 String year = request.getParameter("year");
22 String month = request.getParameter("month");
23 String day = request.getParameter("day");
24
25 int yyyy = Integer.parseInt(year);
26 int mm = Integer.parseInt(month);
27 int dd = Integer.parseInt(day);
28
29 // 2. 처리
30 Calendar cal = Calendar.getInstance();
31 cal.set(yyyy, mm - 1, dd);
32
33 int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
34 char yoil = " 일월화수목금토".charAt(dayOfWeek); // 일요일:1, 월요일:2, ...
35
36 // 3. 출력
37// System.out.println(year + "년 " + month + "월 " + day + "일은 ");
38// System.out.println(yoil + "요일입니다.");
39 response.setContentType("text/html"); // 응답의 형식을 html로 지정
40 response.setCharacterEncoding("utf-8"); // 응답의 인코딩을 utf-8로 지정
41 PrintWriter out = response.getWriter(); // 브라우저로의 출력 스트림(out)을 얻는다.
42 out.println("<html>");
43 out.println("<head>");
44 out.println("</head>");
45 out.println("<body>");
46 out.println(year + "년 " + month + "월 " + day + "일은 ");
47 out.println(yoil + "요일입니다.");
48 out.println("</body>");
49 out.println("</html>");
50 out.close();
51 }
52}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected