JSP _tag

JoMinJun·2021년 4월 4일
0

[Basic] JSP

목록 보기
1/9

html에 java 코드를 사용하기 위한 태그

  • JSP 태그의 종류
  1. 스크립트릿(scriptlet): <% %> 거의 모든 자바코드 기술 가능. - method
  2. 지시자(directive): <%@ %> 페이지 속성을 지정.
  3. 선언자(declaration): <%! %> 변수나 메서드 선언시 사용. - class
  4. 표현식(expression): <%= %> 결과 값을 출력할 때 사용.
  5. 주석(comments): <%-- --%> 코드 주석처리 시에 사용.

html 내부 - java 를 사용 <%@ %>

<%@ 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>

jsp 내부에 jsp 파일 포함시키기

<%@ include file = "header.jspf" %>
<%@ include file = "footer.jspf" %>

<%! %> 클래스 기능 <% %> 매서드 기능 <%= %>

<%! //클래스
public int i;
public String str = "홍길동";
public int add(int n1, int n2){

	return n1 + n2;
}
%>
<% int age = name(); %>


<% //매서드
double a = Math.random();
int result = add(3,2);
int j = 0;
String name= "민준";
%>
<%=name%>입니다.

html 파일 안에 for문을 사용하기


<%for(int i = 0 ;i <10 ; i ++){ %>
<a href = "https://www.naver.com">네이버ㅎ</a>
<%} %>

주석 사용에 따른 - 소스 노출의 유무

<!-- 소스보기 노출 o-->
<%-- 소스보기 노출 x --%>

</body>
</html>
profile
기술정리

0개의 댓글