반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

비전공개미 개발노트

[JSP] 기초, HTML에서 사용방법 본문

프로그래밍/JSP

[JSP] 기초, HTML에서 사용방법

비전공개미 2022. 10. 11. 17:50
반응형
SMALL

<%@ %>  ==>  선언 import, include...

<%= %>    ==>  값을 출력(;세미콜론 생략)

<%! %>     ==>  클래스 변수 선언

 

<%@ 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>
<%
int a = 2;
int b = 3;
int sum = a+b;
out.println("2 + 3 = " + sum);
%>
</body>
</html>
[출력]
2 + 3 = 5

 

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.Date" %>
<!-- import는 가급적 페이지 위에서 선언 / import는 컴마를 기준으로 여러개 작성가능 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<p>
	오늘날짜는 <%=new Date() %>
</p>
</body>
</html>
[출력]
오늘날짜는 Tue Oct 11 17:46:39 KST 2022

 

 

 

<%@ 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>
<%
int a = 10;
int b = 20;
int c = 30;
%>

<%= a + b + c %>
</body>
</html>
[출력]
60

 

 

 

<%@ 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>
<%!
int count = 0;
%>
1이 증가된 후 카운트 값은
<%out.print(++count); %>
</body>
</html>
[출력]
<!-- 새로고침 할때마다 카운트값이 +1 증가 -->
1이 증가된 후 카운트 값은 1

 

 

 

<%@ 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>
<%!
int sum(int a, int b){
	return a + b;
}
%>

<% out.print("2 + 3 = " + sum(2,3)); %>
</body>
</html>
[출력]
2 + 3 = 5

 

 

반응형
LIST
Comments