์ž, ์˜ค๋Š˜์€ ์ปจํŠธ๋กค ํ”Œ๋กœ์šฐ ๋ฌธ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.  

์ปจํŠธ๋กค ํ”Œ๋กœ์šฐ ๋ฌธ๋ฒ•์ด๋ผํ•จ์€ if์™€ ๊ฐ™์€ ์กฐ๊ฑด๋ฌธ๊ณผ for, while๊ณผ ๊ฐ™์€ ๋ฃจํ”„๋ฌธ์„ ๋งํ•ฉ๋‹ˆ๋‹ค. 

1. If-Else

์šฐ์„  if...else ๋ฌธ์— ๋Œ€ํ•ด์„œ ๋ณด๋„๋ก ํ•˜์ฃ .

<%! int day = 3; %>
<html> 
<head><title>IF...ELSE Example</title></head> 
<body>
<% if (day == 1 | day == 7) { %>
      <p> Today is weekend</p>
<% } else { %>
      <p> Today is not weekend</p>
<% } %>
</body> 
</html>

 

๊ฒฐ๊ณผ๋Š” ์•„๋ž˜๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

Today is not weekend

์™œ ์ด๋ ‡๊ฒŒ ๋‚˜์˜ค๋Š”๊ฑด์ง€ ํ•œ์ค„ ํ•œ์ค„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

<%! int day = 3; %>

day๋ผ๋Š” int ํƒ€์ž… ๋ณ€์ˆ˜์— 3์ด๋ผ๋Š” ๊ฐ’์„ ํ• ๋‹นํ–ˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  body ํƒœ๊ทธ ๋‚ด์—์„œ if-else ๋ฌธ์„ ์ด์šฉํ•˜์˜€๋Š”๋ฐ day ๊ฐ’์ด 1 (์ผ์š”์ผ) ์ด๊ฑฐ๋‚˜ 7 (ํ† ์š”์ผ)์ด๋ฉด "Today is weekend"๋ฅผ ์ถœ๋ ฅํ–ˆ๊ฒ ์ง€๋งŒ, ์šฐ๋ฆฌ๋Š” day ๊ฐ’์— 3์„ ํ• ๋‹นํ•ด์ฃผ์—ˆ์œผ๋‹ˆ "Today is not weekend"๊ฐ€ ์ถœ๋ ฅ๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด๋•Œ ์ฃผ์˜ํ•  ์ ์€ if-else ๋ฌธ ๋‚ด์—์„œ ์ถœ๋ ฅํ•˜๊ณ ์ž ํ•˜๋Š” ํƒœ๊ทธ ๋ถ€๋ถ„์€ <% %> ์•ˆ์— ๊ฐ์‹ธ์ง€ ์•Š์•˜๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค.

2. Switch - Case

์ด์ œ switch - case ๋ฌธ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ฃ . 

<%! int day = 3; %> 
<html>
	<head><title>SWITCH...CASE Example</title></head>
    <body> 
    	<% 
        	switch(day) { 
            	case 0: 
                	out.println("It\'s Sunday."); 
                	break; 
                case 1: 
                	out.println("It\'s Monday."); 
                    break; 
                case 2: 
                	out.println("It\'s Tuesday."); 
                    break; 
                case 3: 
                	out.println("It\'s Wednesday."); 
                	break;
                case 4:
                	out.println("It\'s Thursday.");
                    break;
                case 5:
                	out.println("It\'s Friday.");
                    break;
                default:
                	out.println("It's Saturday.");
            } 
        %>
    </body>
</html>

 

์—ญ์‹œ ๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

It's Wednesday.

3. For - Loop

์ด๋ฒˆ์—๋Š” Loop ๋ฌธ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. 

<%! int fontSize; %> 
<html> 
	<head><title>FOR LOOP Example</title></head> 
    <body> 
    	<%for ( fontSize = 1; fontSize <= 3; fontSize++){ %> 
        <p style="font-size:<%= fontSize %>rem"> JSP Tutorial </p> <%}%> 
	</body>
</html>

 

๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

JSP Tutorial

JSP Tutorial

JSP Tutorial

 

4. While - Loop

3๋ฒˆ์—์„œ for ๋ฃจํ”„๋กœ ๊ตฌํ˜„ํ•œ ๊ฒƒ์„ ์ด๋ฒˆ์—๋Š” while๋ฃจํ”„๋ฅผ ์ด์šฉํ•ด์„œ ๊ตฌํ˜„ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

<%! int fontSize; %> 
<html> 
	<head><title>WHILE LOOP Example</title></head> 
    <body> 
    	<%while ( fontSize <= 3){ %> 
            <p style="font-size:<%= fontSize %>rem"> JSP Tutorial </p>
            <%fontSize++;%>
        <%}%> 
	</body> 
</html>

 

๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

JSP Tutorial

JSP Tutorial

JSP Tutorial

JSP Tutorial

 

์ž ์ด์ œ ์–ด๋Š์ •๋„ ๊ฐ์ด ์žกํžˆ์‹œ์ฃ ?

๊ทธ๋ƒฅ ์ž๋ฐ” ๋ฌธ๋ฒ•์„ ๊ทธ๋Œ€๋กœ ์˜ฎ๊ฒจ๋†“๊ธฐ๋งŒ ํ•˜๋Š” ๊ฒ๋‹ˆ๋‹ค.

JSP ์ •๋ง ๋ณ„๊ฑฐ ์•„๋‹ˆ๋„ค์š”~ ใ…Žใ…Ž

while ๋ฃจํ”„๋ฅผ ์ด์šฉํ•œ ๊ฒƒ์„ ์ด๋ฒˆ์—๋Š” do - while์„ ์ด์šฉํ•ด์„œ ํ•œ๋ฒˆ ํ•ด๋ณด์„ธ์š”~ ์ˆ™์ œ์ž…๋‹ˆ๋‹ค~ ใ…‹ใ…‹

 

 

 

Reference : http://www.tutorialspoint.com/jsp/jsp_quick_guide.htm