[JSP] 2021.02.02. DAY_69 JSP 스크립트 태그 연습하기 /구구단, 현재나이 등 _ 배열, Date객체, out객체, 반복문, 조건문
2021. 2. 2. 15:47ㆍWeb_Back-end/JSP
구구단 출력
출력하는 객체 out 사용과, 비사용의 차이
<%@ 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>
<!-- 구구단 2단 -->
<%
//out객체 없이 출력
int dan = 2;
int result = 0;
for(int i=1; i<=9; i++){
result = dan * i;
%>
<%=dan %> x <%=i %> = <%=result %><br><%
}
out.print("<hr>");
//out객체 사용해서 출력
dan = 3;
for(int i=1; i<=9; i++){
out.print(dan + " x " + i + " = " + (dan*i) + "<br>");
}
%>
</body>
</html>
ArrayList
<%@page import="java.util.ArrayList"%>
<%@ 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>
<%
ArrayList<String> list = new ArrayList<String>();
list.add("김포비");
list.add("김밍키");
list.add("박열무");
list.add("박자두");
list.add("남정수");
list.add("신지유");
out.print(list);
%>
<hr>
<%=list %>
</body>
</html>
Date객체 사용
<%@page import="java.util.Date"%>
<%@ 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>
<!-- Date객체 생성, 자신의 나이를 계산하여 나이와 이름 출력하는 jsp작성 -->
<%
int birthYear = 1996;
int thisYear = ((new Date()).getYear())+ 1900;
int age = thisYear - birthYear + 1;
String name = "JJiny";
%>
<h1>이름 : <%=name%></h1>
<h2>나이 : <%=age%></h2>
</body>
</html>
반복문
<%@ 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>
몇월 : <select>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select>
<hr>
<%
out.print("몇월 : <select>");
for(int i=1; i<=12; i++){
out.print("<option>" + i + "</option>");
}
out.print("</select>");
%>
</body>
</html>
'Web_Back-end > JSP' 카테고리의 다른 글
[JSP] 2021.02.03. DAY_70 쇼핑몰 시작페이지 bootstrap css스타일 적용 연습해보기 (0) | 2021.02.03 |
---|---|
[JSP] 2021.02.03. DAY_70 표현식태그, 주석문 (0) | 2021.02.03 |
[JSP] 2021.02.02. DAY_69 bootstrap으로 css스타일 설정하기 (0) | 2021.02.02 |
[JSP] 2021.02.02. DAY_69 JSP 스크립트태그, 로또추첨기 만들기 (0) | 2021.02.02 |
[JSP] 2021.02.02. DAY_69 JSP 기초 (0) | 2021.02.02 |