inputNumber.html
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<style>
div{
width:60%;
margin:0px auto;
text-align:center;
background-color:yellow;
color:green;
}
</style>
</head>
<body>
<form action="createInput.jsp">
<div>
<h2>랜덤 당첨 게임!!</h2>
<fieldset>
<legend>랜덤 숫자 입력</legend>
<input type="number" name="num"><br />
<input type="submit">
</fieldset>
</div>
</form>
</body>
</html>
createInput.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<style>
div {
width: 60%;
margin: 0px auto;
text-align: center;
background-color: yellow;
color: green;
}
</style>
</head>
<body>
<form action="randomWinner.jsp" method="post">
<%
int num = Integer.parseInt(request.getParameter("num"));
%>
<div>
<fieldset>
<legend>랜덤당첨 작성</legend>
주제 : <input type="text" name="menu"><br />
<%
for (int i = 1; i <= num; i++) {
%>
아이템<%=i%>
: <input type="text" name="item"><br />
<%
}
%>
<input type="submit" value="시작">
</fieldset>
</div>
</form>
</body>
</html>
randomWinner.jsp
<%@page import="java.util.Random"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<style>
div {
width: 60%;
margin: 0px auto;
text-align: center;
background-color: yellow;
color: green;
}
</style>
</head>
<body>
<%
request.setCharacterEncoding("EUC-KR");
String menu = request.getParameter("menu");
String[] item = request.getParameterValues("item");
Random rd = new Random();
%>
<div>
<fieldset>
<legend>랜덤 당첨 결과</legend>
<p><%=menu%></p>
<p><%=item[rd.nextInt(item.length)]%></p>
</fieldset>
</div>
</body>
</html>
'Programming > Servlet & JSP' 카테고리의 다른 글
EL 연습하기 (0) | 2020.02.23 |
---|---|
url option (0) | 2020.02.23 |
방문자수 (0) | 2020.02.20 |
방명록(어플리케이션) (0) | 2020.02.20 |
장바구니(쿠키) (0) | 2020.02.20 |