βΆ μ‘μ νκ·Έ
μ‘μ νκ·Έλ JSP νμ΄μ§μμ μλ° μ½λ λ±μ μ€ν¬λ¦½νΈ μΈμ΄λ₯Ό μ¬μ©νμ§ μκ³ λ(μ¦, HTML νκ·Έ ννλ‘) λ€λ₯Έ νμ΄μ§μ μλΈλ¦Ώμ΄λ μλ°λΉμ κ°μ²΄μ μ κ·Όν μ μλλ‘ νκ·Έλ₯Ό μ΄μ©ν΄ ꡬνλ κΈ°λ₯μ λ§νλ€. λν μ΄λ¬ν κΈ°λ₯λ€μ μ€ν¬λ¦½νλ¦Ώ λ±μ μ€ν¬λ¦½νΈ μμ(μλ° μ½λ)λ₯Ό μ¬μ©νμ§ μκΈ° λλ¬Έμ κ°λ°μλ JSP νμ΄μ§μ λ΄λΆμ μΈ νλ‘κ·Έλ¨ λ‘μ§μ μ¬μ©μλ‘λΆν° κ°μΆ μκ° μλ€.
JSPμμ μ 곡νλ μ‘μ νκ·Έλ ν¬κ² λ€μκ³Ό κ°μ΄ λλ μ μλ€.
-νμ΄μ§ νλ¦ μ μ΄ μ‘μ (forward/include μ‘μ )
-μλ°λΉ μ¬μ© μ‘μ (useBean μ‘μ )
-μ νλ¦Ώ μ¬μ© μ‘μ (plugin μ‘μ ) ← μ μ¬μ© μν¨
β
β
β
βΆ forward μ‘μ
forward μ‘μ μ pageContext λ΄μ₯ κ°μ²΄μ forward() λ©μλκ° νκ·Έλ‘ κ΅¬νλ κΈ°λ₯μ΄λ€. λ°λΌμ forward μ‘μ μ νμ¬ νμ΄μ§μ μμ²κ³Ό μλ΅μ κ΄ν μ²λ¦¬κΆμ page μμ±μ μ§μ λ μ΄λν νμ΄μ§λ‘ μꡬμ μΌλ‘ λκΈ°λ κΈ°λ₯μ νλ€. μ¬μ©μκ° requestμ μ§μ ν μμ±λ€μ ν¬μλ©λ νμ΄μ§μμλ κ·Έλλ‘ μ¬μ©ν μ μλ€.
forward μ‘μ μ page μμ±μμ μ§μ λλ μ΄λν νμ΄μ§μ μ£Όμλ λμΌν μΉ μ ν리μΌμ΄μ μ 컨ν μ€νΈ 루νΈλ₯Ό κΈ°μ€μΌλ‘ ν μ λ κ²½λ‘λ μλ κ²½λ‘λ‘λ§ μ§μ μ΄ κ°λ₯νλ€.
μ¦, page μμ±μ μ§μ ν λλ μ€ν€λ§(http://) λΆλΆκ³Ό λλ©μΈ(localhost) λΆλΆ κ·Έλ¦¬κ³ ν¬νΈ λ²νΈλ₯Ό μλ΅ν΄μΌ νλ€.
β
β
forwardTest.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Forward Action Test</title>
</head>
<body>
<h2>ν¬μλ μ‘μ
ν
μ€νΈ</h2>
<form action="forwardTest1.jsp" method="post">
<input type="hidden" name="forwardPage" value="forwardTest2.jsp">
<table>
<tr>
<td>μ΄λ¦ </td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>λμ΄ </td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td>μ£Όμ </td>
<td><input type="text" name="address"></td>
</tr>
<tr><td><input type="submit" value="μ μ‘"></td></tr>
</table>
</form>
</body>
</html>
forwardTest1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("UTF-8"); %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:forward page='<%=request.getParameter("forwardPage") %>'>
<jsp:param name="tel" value="034-1234-5678"/>
</jsp:forward>
</body>
</html>
forwardTest2.jsp
<%@ 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>
<h2>ν¬μλ λ νμ΄μ§(forwardTest2.jsp)</h2>
<table>
<tr>
<td>μ΄λ¦</td>
<td><%=request.getParameter("name") %></td>
</tr>
<tr>
<td>λμ΄</td>
<td><%=request.getParameter("age") %></td>
</tr>
<tr>
<td>μ£Όμ</td>
<td><%=request.getParameter("address") %></td>
</tr>
<tr>
<td>μ νλ²νΈ</td>
<td><%=request.getParameter("tel") %></td>
</tr>
</table>
</body>
</html>
<μ€ν κ²°κ³Ό>
βΆ include μ‘μ νκ·Έ
include μ‘μ μ μμλ‘ μ μ΄κΆμ includeλλ νμ΄μ§λ‘ λκ²Όλ€κ° κ·Έ νμ΄μ§μ μ²λ¦¬κ° λλλ©΄ μ²λ¦¬ κ²°κ³Όλ μλ νμ΄μ§λ‘ λλμμ€κ³ λ€μ μλμ νμ΄μ§λ‘ μ μ΄κΆμ λ°ννλ λ°©μμ΄λ€. λ°λΌμ include μ‘μ μ include μ§μμ΄μ²λΌ μ¬λ¬ νμ΄μ§λ₯Ό ν νμ΄μ§ μμ λ΄λ κΈ°λ₯μ κ°κ³ μλ€.
include μ‘μ μ μ¬λ¬ νμ΄μ§λ₯Ό λμ μΌλ‘ νλμ νμ΄μ§λ‘ λ¬Άμ μ μμΌλ―λ‘ κ°κ°μ νμ΄μ§λ₯Ό κΈ°λ₯λ³λ‘ λͺ¨λνμμΌμ νλμ νμ΄μ§λ₯Ό μ¬λ¬ λͺ¨λνλ νμ΄μ§μ μ§ν©μΌλ‘ νννλ κ²μ΄ κ°λ₯νλ©° μ΄λ¬ν νμ΄μ§λ₯Ό ν νλ¦Ώ νμ΄μ§λΌκ³ νλ€.
β
ββ
includeTest1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Include Action Test</title>
</head>
<body>
<h2>μΈν΄λ£¨λ μ‘μ
ν
μ€νΈ</h2>
<jsp:include page="includeTest2.jsp">
<jsp:param name="name" value="hongkildong"/>
</jsp:include>
</body>
</html>
includeTest2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String name = request.getParameter("name");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<b><%=name %></b>
</body>
</html>
<μ€ν κ²°κ³Ό>
β
β
β
βΆ XMLElementλ₯Ό μμ±νλ μ‘μ νκ·Έλ€
JSPμμ μ 곡νλ XML μλ¦¬λ¨ΌνΈ κ΄λ ¨ μ‘μ νκ·Έλ€μ JSP λ΄μ XML κ΄λ ¨ μ리먼νΈλ€μ λμ μΌλ‘ μμ±νλ μν μ νλ€.
<jsp:element>
<jsp:attribute>
<jsp:body>
β
β
xmlGenerator.jsp
<?xml version="1.0" encoding="UTF-8" ?>
<%@ 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>
<jsp:element name="member">
<jsp:attribute name="id">
member1
</jsp:attribute>
<jsp:body>
μ€μ μ
</jsp:body>
</jsp:element>
</body>
</html>
<μ€ν κ²°κ³Ό>
'JSP' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[JSP] μλ°λΉ (0) | 2021.02.24 |
---|---|
[JSP] μ‘μ νκ·Έλ₯Ό νμ©ν ν νλ¦Ώ νμ΄μ§ μμ± (0) | 2021.02.10 |
[JSP] λ΄μ₯ κ°μ²΄μ μ‘μ νκ·Έ - μμ κ°μ²΄μ μμ± (0) | 2021.02.10 |
[JSP] λ΄μ₯ κ°μ²΄μ μ‘μ νκ·Έ - λ΄μ₯ κ°μ²΄ (0) | 2021.02.10 |
[JSP] μ€ν¬λ¦½νΈ μμ (0) | 2021.02.09 |
λκΈ