ν΄λΌμ΄μΈνΈκ° μμ²ν λ λ§λ€ μλ‘μ΄ request κ°μ²΄κ° μμ±λκ³ , κ°μ μμ²μ μ²λ¦¬νλλ° μ¬μ©λλ λͺ¨λ JSPνμ΄μ§κ° 곡μ ν¨
ν¬μλλ νμ΄μ§κΉμ§ 곡μ κ°λ₯ν¨.
λ¨ νμ΄μ§ μ΄λ μμλ μλ©ΈλΌμ μ¬μ© λΆκ°λ₯ -> page μμλ³΄λ€ μ’ λ λμ
-> νλμ μμ²μ λν μλ΅μ΄ μλ£λ λ μλ©Έ
μμ )
RequestMain.jsp μμ±
<%@page import="common.Person"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setAttribute("requestString", "request μμμ λ¬Έμμ΄");
request.setAttribute("requestPerson", new Person("μμ€κ·Ό", 31));
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2> request μμμ μμ±κ° μμ νκΈ°</h2>
<%
request.removeAttribute("requestString");
//μ‘΄μ¬νμ§ μλ μμ±κ° μ κ±°νλ €κ³ ν΄λ μ€λ₯ μλ¨
request.removeAttribute("requestInteger");
%>
<h2>request μμμ μμ±κ° μ½κΈ°</h2>
<%
Person person = (Person)(request.getAttribute("requestPerson"));
%>
<ul>
<li>String κ°μ²΄ : <%= request.getAttribute("requestString")%></li>
<li>Person κ°μ²΄ : <%= person.getName()%><%=person.getAge() %></li>
</ul>
<h2>ν¬μλλ νμ΄μ§μμ request μμ μμ±κ° μ½κΈ°</h2>
<%
request.getRequestDispatcher("RequestForward.jsp?paramHan=νκΈ¶mEng=English").forward(request, response);
%>
</body>
</html>
ν¬μλ νκΈ° μ μΆλ ₯ νλ©΄

1. request μμμμ String κ°μ²΄μ Person κ°μ²΄ μ μ₯ν¨
2. request.removeλ‘ μμ±κ° μμ ν¨ ( requestString) μ΄λ¦μ΄ μλ μμ±κ° μμ νκ³ μ ν΄λ μ€λ₯ μλ¨
3. μμ±κ° μ½μ΄μ€κΈ°
4. RequestForward.jspλ‘ ν¬μλ© ν¨
μννλ μ½λ : request.getRequestDispatcer("ν¬μλν νμΌ κ²½λ‘").forward(request,response)
RequestForward.jsp νμΌ μμ±
<%@page import="common.Person"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>request μμ </title>
</head>
<body>
<h2>ν¬μλλ‘ μ λ¬λ νμ΄μ§</h2>
<h4>requestMain νμΌμ 리νμ€νΈ μμ μμ± μ½κΈ°</h4>
<%
Person person = (Person)(request.getAttribute("requestPerson"));
%>
<ul>
<li>String κ°μ²΄ : <%= request.getAttribute("requestString")%></li>
<li>Person κ°μ²΄ : <%= person.getName()%><%=person.getAge() %></li>
</ul>
<h4>λ§€κ°λ³μλ‘ μ λ¬λ κ° μΆλ ₯νκΈ°</h4>
<%
request.setCharacterEncoding("UTF-8");
out.println(request.getParameter("paramHan"));
out.println(request.getParameter("paramEng"));
%>
</body>
</html>

requestMainμμ ν¬μλ ν λ ?paramHan=νκΈ¶mEng=English μ΄λΌλ λ§€κ°λ³μλ₯Ό λ£μλ€.
κ·Έλμ ν΄λΉ λ΄μ©λ μΆλ ₯κ°λ₯νλ€
'BACKEND > Java' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
| μΏ ν€(Cookie) λ? (0) | 2023.09.28 |
|---|---|
| Scope ) session μμ (0) | 2023.09.26 |
| Scope ) Page μμ (0) | 2023.09.26 |
| λ°μ΄ν° μ μ‘ κ°μ²΄(DTO) μ€λΉ, μλ°λΉμ¦ (0) | 2023.09.26 |
| [νλ‘κ·Έλλ¨Έμ€] νΌμ λλ λ¨ΉκΈ° (1) (0) | 2023.09.21 |