wasup

JSP) jsp주석표현, jsp코드블럭, 테스트 해보기 본문

IT/Java

JSP) jsp주석표현, jsp코드블럭, 테스트 해보기

wasupup 2021. 5. 4. 14:17
반응형
<%-- 주석 시작
<%@ 지시자 (JSP서버에세 지시) %> 
주석 끝 --%>

<%-- 스크립트 태그 --%> 
<%! ...메소드 정의... %>
<% ...자바코드 블럭... %>
<%= ...표현식코드 블럭... %>

 


 

1. 변수

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<% //자바코드블럭

int a = 7;
int b = 6;
int totla = a+b;

%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<%= //수식 실행블럭
total
%>

start jsp project

</body>
</html>

2. for문

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

<nav>
	<ul>
		<%
		for( int i = 0; i <= 5; i++){
		 %>
		<li>
			<a href="#none" title="">menu<%= i %></a>
			<%=  %>
		</li>
		<%
		}
		 %>
	</ul>
</nav>

</body>
</html>


3. if문

<%@ 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 = 7;
	if(a<0){
%>
		a is small
<%
	}else{
%>
		a is big
<%
	}
%>
</body>
</html>

4. boolean

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%
	boolean login = false;
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
		if (login == true) {
	%>
	환영합니다.
	<button>logout</button>
	<%
		} else {
	%>

	<label for="id" id="label_id_area" class="label_l blind">아이디</label>
	<input type="text" id="id" name="id" placeholder="아이디" maxlength="41"
		value="">
	<label for="pw" id="label_pw_area" class="label_l blind">비밀번호</label>
	<input type="password" id="pw" name="pw" placeholder="비밀번호"
		maxlength="16">
	<br/>
	<button>login</button>
	<button>join</button>
	<%
		}
	%>

</body>
</html>

 

반응형
Comments