티스토리 뷰
(기초)그래서 뭘 배운거야?/JSP
JSP-08-request.setAttribute()/getAttribute() : 데이터 설정, 받아오기
Soheny.P 2021. 11. 1. 21:27728x90
<%@ 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>
<%
// request.setAttribute : 오브젝트를 키워드로 request에 저장시 사용하는 메서드
// request.getAttribute : 오브젝트에 담긴 데이터를 request로 가져올 때 사용하는 메서드
request.setAttribute("id", "abcd");
request.setAttribute("pw", "1234");
//값들이 null로 나옴
//response.sendRedirect("example4_1.jsp");
//지정값이 정상적으로 나옴
pageContext.forward("example4_1.jsp");
%>
</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형으로 오기 때문에 String으로 형변환 필요
String id = (String)request.getAttribute("id");
String pw = (String)request.getAttribute("pw");
%>
<h1>example4.jsp에서 받은 데이터</h1>
<p>id : <%=id %></p>
<p>pw : <%=pw %></p>
</body>
</html>
>실행은 example4.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>
<%
request.setAttribute("id", "abcd");
request.setAttribute("pw", "1234");
%>
<jsp:forward page="example5_1.jsp"></jsp:forward>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String id = (String)request.getAttribute("id");
String pw = (String)request.getAttribute("pw");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>example5_1.jsp 페이지 입니다.</h1>
<p><%=id %></p>
<p><%=pw %></p>
</body>
</html>
728x90
'(기초)그래서 뭘 배운거야? > JSP' 카테고리의 다른 글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 정보처리기사실기
- 2021년2회
- 합격
- spantag
- br tag
- marktag
- 정보처리기사
- 정처기
- html
- 2021년42회
- tablespan
- ptag
- 복습
- 비전공
- 줄글
- tabletag
- boldtag
- pretag
- usemap
- ol>li
- 긴문장
- ul>li
- emtag
- imgtag
- 93점
- 단락태그
- hn태그
- hr tag
- definition List
- 정보처리기사필기
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함