<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String str = "Hello jsp";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- HTML 주석문 -->
<%--
JSP 주석문
JSP : Java Server Page
client ------ > server(WAS) < ------ > server(DB)
request java + html
localhos:8080/sample
web server
web container
servlet, jsp
(get, post) -> 보안
< ------ 해석
response
Spring Framework MyBatis Framework
Servlet = Java(HTML)
JSP = HTML(Java)
= html, javascript, css, jquery, java
--%>
<h1>Hello JSP</h1>
<%
// Java 영역
// Scriptlet = script + applet
System.out.println("console 출력");
/*
내장(암시)객체 : new를 하지 않고 바로 사용할 수 있는 Object
request, response, session, out
HttpServletRequest
*/
out.println("<p>Web 출력</p>");
%>
<%
out.println("<h3>Hello Jsp</h3>");
%>
<%
System.out.println("str = " + str);
out.println("str = " + str);
%>
<br>
<!--해당 value만 취득-->
<%=str %>
<br><br>
<%
for (int i = 0; i< 10; i++){
%>
<p id="demo">P tag <%=i + 1%></p>
<% } %>
<%
for(int i = 0; i< 10; i++) {
out.println("<p class= 'demo'> P Tag" + (i + 1) + "</p>");
}
%>
<p id="demo">p demo</p>
<script>
document.getElementById("demo").innerHTML = "change p tag content"
</script>
</body>
</html>
<%@ 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>
<%-- scriptlet의 영역--%>
<%!
// 선언의 영역: 변수(global)를 선언, 함수선언, 클래스선언
int gl_var = 0;
public void func(){
System.out.println("func() 호출");
}
%>
<%
// 코드 부
gl_var++;
int var = 0;
var++;
out.println("gl_var = " + gl_var);
out.println("var = " + var);
func();
%>
<br>
<%=gl_var%>
</body>
</html>
<%@ 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>
<%
// 내장객체: 동적할당 하지 않고 사용할 수 있는 Object
// request -> getParameter, setAttribute, getAttribute
// response -> sendRedirect
// out
// session
String name = request.getParameter("name"); // form <input type="text"
System.out.println("name:" + name); // <a
// location.href
// submit();
String age = request.getParameter("age");
System.out.println("age: " + age);
String hobby[] = request.getParameterValues("hobby"); //checkbox
if(hobby != null){
for(int i = 0; i < hobby.length; i++){
System.out.println("hobby = " + hobby[i]);
}
}
%>
</body>
</html>