[Web] Day 2 - JSP

sueยท2024๋…„ 1์›” 4์ผ

๐Ÿ“’๊ตญ๋น„ํ•™์› [Web]

๋ชฉ๋ก ๋ณด๊ธฐ
4/21
post-thumbnail
  • jsp์“ฐ๋Š” ์˜์—ญ

1. JSP์˜์—ญ / HTML์˜์—ญ ๊ตฌ๋ถ„ํ•ด์„œ ํ•ฉ๊ณ„ ์ถœ๋ ฅ

Test1.

๐Ÿ’ป ์ž…๋ ฅ

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

	int a=10, b=5, c;
	
	c = a + b;

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

</body>

ํ•ฉ: <%=a%>+<%=b %>=<%=c %><br/>

<%

	out.print("ํ•ฉ: " + a + "+" + b + "=" + c + "<br/>");

	String str = String.format("ํ•ฉ: %d+%d=%d<br/>",a,b,c);
	
	out.print(str);


%>

</html>

๐Ÿ“Œ ์ถœ๋ ฅ


์„œ๋ธ”๋ฆฟ์˜ ๊ฐ์ฒด (๋‚ด์žฅ๊ฐ์ฒด)

ํŽ˜์ด์ง€ ์†Œ์Šค๋ณด๊ธฐ

  • jsp์˜์—ญ์•ˆ์—์„œ html์„ ์“ฐ๊ณ ์‹ถ์œผ๋ฉด
    out.print("
    ")์ฒ˜๋Ÿผ ์ถœ๋ ฅ์–ด + ๋”ฐ์˜ดํ‘œ์จ์ฃผ๋ฉด ๋จ

โ–ผ html์˜์—ญ์•ˆ์—์„œ๋„ jsp์˜์—ญ์„ ๋งŒ๋“ค๊ณ ์‹ถ์œผ๋ฉด


2. ํ†ฐ์บฃ & ์ดํด๋ฆฝ์Šค ๊ณต์šฉ๊ณต๊ฐ„

Test2.

๐Ÿ’ป ์ž…๋ ฅ

ํ†ฐ์บฃ & ์ดํด๋ฆฝ์Šค ๊ณต์šฉ๊ณต๊ฐ„

C:\java\work.metadata.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\study\org\apache\jsp\jsp1

C:\java\work\study\WebContent

C:\java\work.metadata.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\study
์ด study๊ฐ€
์ฃผ์†Œ
http://192.168.16.16:8080/study/jsp1/test1.jsp
์—ฌ๊ธฐ study์ž„


โญโญโญ

3.

Test3.

๐Ÿ’ป ์ž…๋ ฅ

๐Ÿ“Œ ์ถœ๋ ฅ

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

<%!

	int a = 0;

	int sum(int x){
		
		int s=0;
		
		for(int i=1; i<=x; i++){
			s+=i;
		}
		
		return s;
		
	}

%>

<%

	int b = 0;

a++;
b++;

%>



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

a: <%=a %><br/>
b: <%=b %><br/>

ํ•ฉ: <%=sum(100) %>


</body>
</html>

0๊ฐœ์˜ ๋Œ“๊ธ€