forked from castello/spring_basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoDice.java
More file actions
31 lines (27 loc) · 1023 Bytes
/
TwoDice.java
File metadata and controls
31 lines (27 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.fastcampus.ch2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@Controller
public class TwoDice {
@RequestMapping("/rollDice")
// public static void main(String[] args) {
public void main(HttpServletResponse response) throws IOException {
int idx1 = (int)(Math.random()*6)+1;
int idx2 = (int)(Math.random()*6)+1;
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body>");
out.println("<img src='resources/img/dice"+idx1+".jpg'>");
out.println("<img src='resources/img/dice"+idx2+".jpg'>");
out.println("</body>");
out.println("</html>");
out.close();
}
}