1. 페이지 디렉티브(page directive) 필수!
2. 선언부
<%= %>
jsp 파일 실행 - html 실행결과
-java
-class
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
</head>
<body>
<table border="1">
<%
for(int i=1; i<=9; i++){
out.println("<tr>");
out.println("<td width='100' align='center'>1" +" X " +i +" = " +(1*i) +"</td>");
out.println("</tr>");
}
%>
</table>
</body>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
</head>
<body>
<table border="1">
<%
String result = "";
for(int i=1; i<=9; i++){
result += "<tr>";
result += "<td width='100' align='center'>1" +" X " +i +" = " +(1*i) +"</td>";
result += "</tr>";
}
%>
</table>
</body>
<table border="1">
<%=result %>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
</head>
<body>
<table border="1">
<%
StringBuffer sb = new StringBuffer();
for(int i=1; i<=9; i++){
sb.append("<tr>");
sb.append("<td width='100' align='center'>1" +" X " +i +" = " +(1*i) +"</td>");
sb.append("</tr>");
}
%>
</table>
</body>
<table border="1">
<%=sb %>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
</head>
<body>
<table border="1">
<%
StringBuffer sb = new StringBuffer();
for(int j=0; j<=9; j++){
sb.append("<tr>");
for(int i=0; i<=9; i++){
if(i!=0 && j!=0){
sb.append("<td width='100' align='center'>" +j +" X " +i +" = " +(j*i) +"</td>");
}else if(j==0 && i==0){
sb.append("<td width='100' align='center'>" +" " +"</td>");
}else if(j==0){
sb.append("<td width='100' align='center'>" +"x" +i +"</td>");
}else{
sb.append("<td width='100' align='center'>" +j +"단" +"</td>");
}
}
sb.append("</tr>");
}
%>
</table>
</body>
<table border="1">
<%=sb %>
</body>
</html>
2. 선언부
멤버변수나 멤버메서드
3. 스크립틀릿(scriptlet
<% ~~~ %>
<% ~~~ %>
자바코드 : 지역변수, 제어문...
4. 표현식(expression)<%= %>
jsp 파일 실행 - html 실행결과
-java
-class
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
</head>
<body>
<table border="1">
<%
for(int i=1; i<=9; i++){
out.println("<tr>");
out.println("<td width='100' align='center'>1" +" X " +i +" = " +(1*i) +"</td>");
out.println("</tr>");
}
%>
</table>
</body>
</body>
</html>
<html>
<head>
</head>
<body>
<table border="1">
<%
String result = "";
for(int i=1; i<=9; i++){
result += "<tr>";
result += "<td width='100' align='center'>1" +" X " +i +" = " +(1*i) +"</td>";
result += "</tr>";
}
%>
</table>
</body>
<table border="1">
<%=result %>
</body>
</html>
<html>
<head>
</head>
<body>
<table border="1">
<%
StringBuffer sb = new StringBuffer();
for(int i=1; i<=9; i++){
sb.append("<tr>");
sb.append("<td width='100' align='center'>1" +" X " +i +" = " +(1*i) +"</td>");
sb.append("</tr>");
}
%>
</table>
</body>
<table border="1">
<%=sb %>
</body>
</html>
<html>
<head>
</head>
<body>
<table border="1">
<%
StringBuffer sb = new StringBuffer();
for(int j=0; j<=9; j++){
sb.append("<tr>");
for(int i=0; i<=9; i++){
if(i!=0 && j!=0){
sb.append("<td width='100' align='center'>" +j +" X " +i +" = " +(j*i) +"</td>");
}else if(j==0 && i==0){
sb.append("<td width='100' align='center'>" +" " +"</td>");
}else if(j==0){
sb.append("<td width='100' align='center'>" +"x" +i +"</td>");
}else{
sb.append("<td width='100' align='center'>" +j +"단" +"</td>");
}
}
sb.append("</tr>");
}
%>
</table>
</body>
<table border="1">
<%=sb %>
</body>
</html>
'Study > Programming' 카테고리의 다른 글
JSP DB연동 (0) | 2009.05.27 |
---|---|
JSP 날짜 구하기 (0) | 2009.05.27 |
자바 TCP MultiChat (0) | 2009.05.26 |
자바 Server, Client (0) | 2009.05.26 |
자바 Network Chat (0) | 2009.05.26 |