32-2: Servlet lotto.jsp

jk·2024년 2월 16일
0

kdt 풀스택

목록 보기
63/127



1. 아래를 프로그래밍 하시오.

/context명/lotto.jsp ->버튼 하나
/context명/lotto_num.jsp ->로또 번호 6개 출력
 
- 최대한 액션태그를 활용해 주세요
<!-- code1 -->
<!-- ./WebContent/lotto.jsp -->
<%@ 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>
//code2
//./src/game/Lotto.java
package game;
public class Lotto {
	private StringBuilder print;
	public Lotto() {
	}
	public StringBuilder getPrint() {
		return print;
	}
	public void setPrint(StringBuilder print) {
		this.print = print;
	}
}
<!-- code3 -->
<!-- ./WebContent/lotto_num.jsp -->
<%@ 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("&nbsp&nbsp&nbsp&nbsp");
		};
	%>
	<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>


profile
Brave but clumsy

0개의 댓글