μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- Kλ°°ν°λ¦¬
- database
- λ μ
- κ°λ°
- μν
- μλ°
- μ€λΈμ
- ν°μ€ν 리μ±λ¦°μ§
- css
- html
- μ±
- κΉλ―Έκ²½μλ§νμμ
- λΌνλΌμ€μλ§λ
- νμ΄μ¬
- Kλ°°ν°λ¦¬λ 볼루μ
- μ½λ©
- μΉνμ΄μ§λ§λ€κΈ°
- μλ°μ€ν¬λ¦½νΈ
- μ»΄ν¨ν°κ³Όν
- Python
- Java
- 리μ‘νΈ
- JavaScript
- ComputerScience
- νλ‘κ·Έλλ°
- μΉνΌλΈλ¦¬μ±
- λ§μΌλ΄κ°μΈμμλ€μμ°λ€λ©΄
- λ°μν
- μ€λΌν΄
- λ°μ΄ν°λ² μ΄μ€
- Today
- Total
JiYoung Dev π₯
[JSP/Servlet] μ μΈλ¬Έ, μ§μμ, λ΄μ₯κ°μ²΄ (2023.05.16) λ³Έλ¬Έ
[JSP/Servlet] μ μΈλ¬Έ, μ§μμ, λ΄μ₯κ°μ²΄ (2023.05.16)
Shinjio 2023. 5. 16. 20:01π μ μΈλ¬Έ(Declaration)
μ μΈλ¬Έ λ΄ μμ±ν λ³μ
- μμΉλ ν΄λμ€ λ°λ‘ λ°μ (μ μλ³μ)
μ€ν¬λ¦½νΈλ¦Ώ λ΄ μμ±ν λ³μ
- service λ©μλ μμΌλ‘ λ€μ΄κ° (μ§μλ³μ)
π μ§μμ(Directive)
π Page μ§μμ
λΆκ°λ₯νκ±Έ μ»΄ν¨ν°μκ² μν€λ©΄? ERROR λ°μ
μ€λ₯ λ°μμ νΉμ νμ΄μ§ μ°κ²°λλλ‘!
νμ¬νμ΄μ§
errorPage="μ€λ₯λ°μμ 보μ¬μ€ νμ΄μ§"
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" errorPage="Ex04ErrorPage.jsp"%>
<!-- errorPage : νμ¬ νμ΄μ§μμ μ€λ₯κ° λ°μνμ λ λμ 보μ¬μ€ νμ΄μ§ μ§μ -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%=2/0 %>
</body>
</html>
μ€λ₯ λ°μμ 보μ¬μ€ νμ΄μ§
isErrorPage="true"
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isErrorPage="true"%>
<!-- μ΄ νμ΄μ§κ° μ€λ₯κ° λ°μνμ λ 보μ¬μ€ νμ΄μ§μμ μ§μ ! -->
<!-- >> isErrorPage : false(κΈ°λ³Έκ°) -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body align="center">
<img src="./img/error.png" width="300px" height="300px"><br><br>
μλ² μ€λ₯λ₯Ό μ κ²μ€μ
λλ€
</body>
</html>
π Include μ§μμ
<%@ include file="μ°κ²°ν νμ΄μ§ νμΌ" %>
<%@ 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>
<%@ include file="Ex05header.jsp" %> <br>
λ©μΈνμ΄μ§<br>
<a href="Ex05sub.jsp">μλΈ νμ΄μ§λ‘ μ΄λ</a><br>
<%@ include file="Ex05footer.jsp" %>
</body>
</html>
π Taglib μ§μμ
λΌμ΄λΈλ¬λ¦¬ λ€μ΄λ‘λ
λ€μ΄λλ―Ή μΉνλ‘μ νΈμμ λΌμ΄λΈλ¬λ¦¬ μ¬μ©ν λ
WEB-INF > lib ν΄λ λ΄μ μ½μ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="C" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%for(int i=1; i<=10; i++){ %>
<%=i %>
<%} %>
<br>
<C:forEach var="i" begin="1" end="10" step="1">
<!-- el λ¬Έλ² : νΉμ μμμ μ μ₯λ κ°μ μ¬μ©ν μ μλλ‘ ν΄μ£Όλ λ¬Έλ² -->
<C:out value="${i}"/>
</C:forEach>
</body>
</html>
π μ£Όμ
html μ£Όμμ μ¬μ©μμκ²λ 보μ¬μ§ μ μλ€ >> 보μμ μ€μν κ²μ μ°λ©΄ μλ¨!
μλ° νμΌλ‘ λ³νλμ λκΉμ§ νμΈ κ°λ₯
jsp μ£Όμμ 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>
<!-- HTML μ£Όμ : μ΅μ’
μλ΅ λ¬Έμμμ νμΈ κ°λ₯ -->
<% //μλ° μ£Όμ : μλ° νμΌλ‘ λ³νλμ λκΉμ§ νμΈ κ°λ₯ %>
<%-- JSP μ£Όμ : JSP νμΌμμλ§ νμΈ κ°λ₯ --%>
</body>
</html>
π λ΄μ₯κ°μ²΄(Implicit Object)
JSP νμ΄μ§ λ΄λΆμμ out, request λ±μ κ°μ²΄λ λ°λ‘ μμ±νμ§ μλλΌλ λ°λ‘ μ¬μ© κ°λ₯ν μ΄μ λ?
λ΄μ₯κ°μ²΄ λλ¬Έ! --> JSP νμ΄μ§ μμ μ μΈνμ§ μκ³ λ μ¬μ©ν μ μλ κ°μ²΄
out.printλ‘ μ¬μ©
μ€μ΅1.
HTML μ½λ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<fieldset>
<legend>νμ νμΈνλ‘κ·Έλ¨</legend>
<form action="Ex01Request.jsp">
<table>
<tr>
<td>μ΄λ¦</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Javaμ μ</td>
<td><input type="text" name="java"></td>
</tr>
<tr>
<td>Webμ μ</td>
<td><input type="text" name="web"></td>
</tr>
<tr>
<td>IoTμ μ</td>
<td><input type="text" name="iot"></td>
</tr>
<tr>
<td>Androidμ μ</td>
<td><input type="text" name="and"></td>
</tr>
<tr>
<td><input type="submit" value="νμ νμΈ"></td>
</tr>
</table>
</form>
</fieldset>
</body>
</html>
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>
<fieldset>
<legend>νμ νμΈνλ‘κ·Έλ¨</legend>
<form action="Ex01Request.jsp">
<%
int java = Integer.parseInt(request.getParameter("java"));
int web = Integer.parseInt(request.getParameter("web"));
int iot = Integer.parseInt(request.getParameter("iot"));
int and = Integer.parseInt(request.getParameter("and"));
%>
<table align="center">
<tr>
<td>μ΄λ¦</td>
<td><% out.print(request.getParameter("name")); %></td>
</tr>
<tr>
<td>Javaμ μ</td>
<td><%= java %></td>
</tr>
<tr>
<td>Webμ μ</td>
<td><%= web %></td>
</tr>
<tr>
<td>IoTμ μ</td>
<td><%= iot %></td>
</tr>
<tr>
<td>Androidμ μ</td>
<td><%= and %></td>
</tr>
<tr>
<td>νκ· </td>
<% double avg = (java + web + and + iot)/4.0;
String score = "";
if(avg >= 95){
score = "A+";
}else if(avg >= 90){
score = "A";
}else if(avg >= 85){
score = "B+";
}else if(avg >= 80){
score = "B";
}else {
score = "F";
}
%>
<td><%= avg %></td>
</tr>
<tr>
<td>νμ </td>
<td><strong><%= score %></strong></td>
</tr>
</table>
</form>
</fieldset>
</body>
</html>
μ€μ΅ 2.
html μ½λ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body align="center">
<h1>λλ€ λΉμ²¨ κ²μ</h1>
<fieldset>
<legend>λλ€λ½κΈ°</legend>
<form action="Ex02createInput.jsp">
<input type="number" name="num">
<br><br>
<input type="submit" value="μμ±νκΈ°">
</form>
</fieldset>
</body>
</html>
jsp 1 μ½λ (μ λ ₯)
<%@ 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 align="center">
<h1>λλ€ λΉμ²¨ κ²μ</h1>
<fieldset>
<legend>λλ€λ½κΈ°</legend>
<form action="Ex02randomOutput.jsp">
μ£Όμ :
<input type="text" name="subject">
<br>
<%
for(int i = 1 ; i <= Integer.parseInt(request.getParameter("num")); i++){
out.print("μμ΄ν
: ");
out.print("<input type='text' name='item'>");
out.print("<br>");
}
%>
<input type="submit" value="λλ€λ½κΈ°">
</form>
</fieldset>
</body>
</html>
jspμ½λ(μΆλ ₯)
<%@page import="java.util.Random"%>
<%@ 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 align="center">
<h1>λλ€ λΉμ²¨ κ²μ</h1>
<fieldset>
<legend>λλ€λ½κΈ°κ²°κ³Ό</legend>
<form action="Ex02createInput.jsp">
<%
String[] items = request.getParameterValues("item");
Random rd = new Random();
int ran = rd.nextInt(items.length);
String print = items[ran];
%>
<%= request.getParameter("subject") %>
<br>
<%= print%>
</form>
</fieldset>
</body>
</html>
'full stack > Back-End' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[JSP/Servlet] μΈμ (session) (2023.05.18) (0) | 2023.05.19 |
---|---|
[JSP/Servlet] Scope (2023.05.18~19) (0) | 2023.05.19 |
[JSP/Servlet] JSP νμμ±κ³Ό νΉμ§, ꡬμ±μμ (2023.05.15) (0) | 2023.05.15 |
[JSP/Servlet] λ°μ΄ν° μ μ‘ GET/POST(2023.05.12) (0) | 2023.05.12 |
[JSP/Servlet] Servlet κ°μ, λ°μ΄ν° μ μ‘ (2023.05.10) (0) | 2023.05.12 |