JSP
[JSP] 35. JSP를 통해 구구단 출력 페이지 만들기
Song hyun
2024. 7. 5. 10:16
728x90
반응형
[JSP] 35. JSP를 통해 구구단 출력 페이지 만들기
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String mHidden="홍길동";
%>
<h1>구구단에 사용할 숫자를 입력하시오</h1>
<form action="result.jsp" method="get">
<input type="hidden" name="mHidden" value="<%=mHidden%>">
<input type="number" name="number" value="7">
<input type="submit" value="제출">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>구구단 결과</title>
</head>
<body>
<h1>구구단 결과</h1>
<%
String sessionId=session.getId();
out.print("sessionId: "+sessionId);
String numStr=request.getParameter("number");
int number=Integer.parseInt(numStr); // 예외 처리 생략
%>
<h2><%=number %> 단</h2>
<table border="1">
<thead>
<tr>
<th>계산식</th>
<th>결과</th>
</tr>
</thead>
<tbody>
<%for(int i=1; i<10; i++){%>
<tr>
<td><%=number %> x <%= i %></td>
<td><%=number * i%></td>
</tr>
<%}%>
</tbody>
<tfoot></tfoot>
</table>
</body>
</html>
728x90
반응형