MapleStory Finger Point

๐ŸŸค JAVA/๐ŸŸค JSP

[JSP] ์Šคํฌ๋ฆฝํŠธ ์š”์†Œ ๋ž€?

HYEJU01 2024. 8. 23. 23:58

๐Ÿ”น   ์Šคํฌ๋ฆฝํŠธ ์š”์†Œ 

๋ฌธ์„œ์˜ ๋‚ด์šฉ์„ ๋™์  ์ƒ์„ฑ ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” ๊ฒƒ 

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ or ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

 

[ ์Šคํฌ๋ฆฝํŠธ๋ฆฟ Scriptlet ]  ์ž๋ฐ” ์ฝ”๋“œ ์‹คํ–‰
JSP ํŽ˜์ด์ง€์—์„œ๋Š” JAVA ์–ธ์–ด ์‚ฌ์šฉ์„ ์œ„ํ•œ ์š”์†Œ ์ค‘ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ํƒœ๊ทธ 

 

[ ์„ ์–ธ Declaration ]  ์ž๋ฐ” ๋ฉ”์„œ๋“œ ์ƒ์„ฑ
์—ฌ๊ธฐ์— ์„ ์–ธํ•˜๋ฉด ์ „์—ญ ๋ณ€์ˆ˜, ๋ฉ”์„œ๋“œ๋กœ ์‚ฌ์šฉ

 

[ ํ‘œํ˜„์‹ Expression ]  ๊ฐ’ ์ถœ๋ ฅ
๋ณ€์ˆ˜ ๊ฐ’, ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ ๊ฒฐ๊ณผ ๊ฐ’ ์ถœ๋ ฅ์„ ์œ„ํ•ด ์‚ฌ์šฉ

 

[ ์ฃผ์„ Comments ] 
์‹ค์ œ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์—๋Š” ์˜ํ–ฅ์ด ์—†๊ณ , ํ”„๋กœ๊ทธ๋žจ ์„ค๋ช… ๋ชฉ์ 

 

 

[ JSP ํƒœ๊ทธ ์ข…๋ฅ˜ ]

<% %> ์ž๋ฐ” ์ฝ”๋“œ ๊ธฐ์ˆ  [ ์Šคํฌ๋ฆฝํŠธ๋ฆฟ Scriptlet ] 
<%@ %> ํŽ˜์ด์ง€ ์†์„ฑ [ ์ง€์‹œ์ž  directive ]
<%! %> ๋ณ€์ˆ˜, ๋ฉ”์„œ๋“  ์„ ์–ธ [ ์„ ์–ธ Declaration ]
<%= %> ๊ฒฐ๊ณผ๊ฐ’ ์ถœ๋ ฅ [ ํ‘œํ˜„์‹ Expression ]
<%-- %> ์ฝ”๋“œ ์ฃผ์„ [ ์ฃผ์„ Comments ] 

 

 

๐Ÿ”น ์Šคํฌ๋ฆฝํŠธ๋ฆฟ (Scriptlet) 

JSP ํŽ˜์ด์ง€์—์„œ ์ž๋ฐ” ์ฝ”๋“œ ์‹คํ–‰ ์‹œ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ ๋ธ”๋ก

 

<%
int sum = 0;
sum += 1;
%>

 


๐Ÿ”น ํ‘œํ˜„์‹ (Expression) 

๊ฐ’์„ ์ถœ๋ ฅ ๊ฒฐ๊ณผ์— ํฌํ•จ์‹œํ‚ฌ ๋•Œ ์‚ฌ์šฉ

<%
int sum = 0;
sum += 1;
%>

sum ๊ฐ’์€ <%= sum %> ์ž…๋‹ˆ๋‹ค.

 

 

 

๐Ÿ”น ์„ ์–ธ๋ถ€ (Declaration) 

์ž๋ฐ” ๋ฉ”์„œ๋“œ์™€ ๋™์ผํ•˜๋‹ค!

<%!
public int sum(int a, int b){
    int c = a * b;
    return c;
}
%>


<%= sum(1,2) %>