1. 아래를 프로그래밍 하시오.
/context명/lotto.jsp ->버튼 하나
/context명/lotto_num.jsp ->로또 번호 6개 출력
- 최대한 액션태그를 활용해 주세요
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>lotto.jsp</title>
</head>
<body>
<form action="lotto_num.jsp" method="post">
<input type="submit" value="BET">
</form>
</body>
</html>
package game;
public class Lotto {
private StringBuilder print;
public Lotto() {
}
public StringBuilder getPrint() {
return print;
}
public void setPrint(StringBuilder print) {
this.print = print;
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
import="java.util.concurrent.ThreadLocalRandom"
import="java.util.*"
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>lotto_num.jsp</title>
</head>
<body>
<%
final int LOTTO_SIZE = 6;
final int LOTTO_MIN = 1;
final int LOTTO_MAX = 45;
Set<Integer> lottoNumbers = new HashSet<Integer>();
while(lottoNumbers.size() < LOTTO_SIZE) {
int randomNumber = ThreadLocalRandom.current().nextInt(LOTTO_MIN, LOTTO_MAX + 1);
lottoNumbers.add(randomNumber);
};
StringBuilder print = new StringBuilder();
for(int i : lottoNumbers) {
print.append(i);
print.append("    ");
};
%>
<jsp:useBean id="lotto" class="game.Lotto"/>
<jsp:setProperty name="lotto" property="print" value="<%=print%>"/>
<jsp:getProperty property="print" name="lotto"/>
<br>
<a href="lotto.jsp">One more...</a>
</body>
</html>