JSP 구구단 출력
gugudan.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>구구단</title>
</head>
<body>
<h2>구구단 출력하기</h2>
<form action="gugudan.jsp" method="post">
구구단 단수 입력 : <input type="number" name="dan" autofocus="autofocus" required="required"><br>
<input type="submit" value="제출">
</form>
</body>
</html>
gugudan.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>구구단 출력하기</title>
</head>
<body>
<h2>구구단 출력하기</h2>
<%
int dan = Integer.parseInt(request.getParameter("dan")); // 구구단 단수
int gob = 0;
%>
<table border="1">
<%
for(int i = 1; i<10; i++) {
gob = dan * i;
%>
<tr><td> <%=dan%> X <%=i %> = <%=gob %></td></tr>
<%} %>
</table>
</body>
</html>
결과
Leave a comment