<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>for</title>
</head>
<body>
<%-- <%
int sum = 0;
for (int i=1; i<=10; i++) {
if(i < 10)
out.print(i + " + ");
else
out.print(i + " = ");
sum += i;
}
%> --%>
<%
int sum = 0;
for (int i=1; i<=10; i++) {
if(i < 10) { // jsp를 끊었다가 쓸때는 반드시 중괄호를 해준다
%>
<%=(i + " + ") %>
<%
} else {
%>
<%=(i + " = ") %>
<%
}
sum += i;
}
%>
<%=sum %><br><br>
<%
int arr[] = new int[10];
for(int i=0; i<arr.length; i++) {
arr[i] = i+1;
//out.print(arr[i] + "<br>");
%>
<%=arr[i] + "<br>" %>
<%
}
%>
</body>
</html>
while문
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>while</title>
</head>
<body>
<form action="07.2.while.jsp">
반복하고 싶은 문구 : <input name="msg"><br>
반복하고 싶은 횟수 : <input type="number" name="count"><br>
<button>서버로 전송</button>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>while_2</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
String msg = request.getParameter("msg");
int count = Integer.parseInt(request.getParameter("count"));
int num = 0;
while(count > num) {
%>
<%=msg %><br>
<%
++num;
}
%>
</body>
</html>'Back-end > JSP' 카테고리의 다른 글
| [JavaSpring] page_include (0) | 2024.07.16 |
|---|---|
| [JavaSpring] trimWhitespace, userErrorPage (0) | 2024.07.16 |
| [JavaSpring] page_info (0) | 2024.07.16 |
| [JavaSpring] if문 (0) | 2024.07.15 |
| [JavaSpring] Hello JavaSpring (0) | 2024.07.15 |