비전공개미 개발노트
[JSP] 기초, HTML에서 사용방법 본문
반응형
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
'프로그래밍 > JSP' 카테고리의 다른 글
[JSP] jsp:include를 사용해 페이지 불러오기 (1) | 2022.10.11 |
---|---|
[JSP] jsp:forward를 사용해 페이지 불러오기 (1) | 2022.10.11 |
[JSP] web.xml파일을 이용해 초기 id, pw 설정 및 확인 (0) | 2022.10.11 |
[JSP] include로 header / footer 붙이기 (0) | 2022.10.11 |
[JSP] 값이 틀릴시 errorPage로 이동 (0) | 2022.10.11 |
Comments