현재

[JSP] EL(Expression Language) 본문

웹 프로그래밍/JSP

[JSP] EL(Expression Language)

AAAge 2023. 10. 19. 17:16

자바에서 작성한 코드를 JSP에서 사용하기 위하여 사용한다.

session.setAtrribute(key=String, Value=Object); 로 저장공간을 나눠서 설정을 저장해준다.

만약 같은 key값이 있으면 page,request,session,application 순으로 불러온다.

!!!하지만 절때 이런식으로 같은 key값을 저장해서는 안된다!!!

 

파일위치 : webapp/el.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
/* 
	EL: ${}
	4가지 저장 공간과 관련 있다.
*/

	String str1 = "안녕하세요";

	session.setAttribute("eee1", 333);	//서로 저장공간이 달라서 session.eee1 에 333,request.eee1에 444저장댐
	request.setAttribute("eee1", 444);	//그럼 eee1을 출력했을때 뭐가 나올것인가... 
	
	request.setAttribute("q1", str1); //Map 계열이기 때문에 덮어씌어진다
	request.setAttribute("n", 1234);

	session.setAttribute("rrr", str1);
	
%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	${q1}<br>
	${n}<br>
	${eeee}<br> <!-- 해당 값 없어서 출력 안함, exception이 발생하진 않음 -->
	${rrr}<br>
	${eee1}
</body>
</html>

 

파일위치 : webapp/el2.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%
	application.setAttribute("a", 1);	//현재 서로다른 4개의 공간에 "a"라는 이름의 변수가 저장
	session.setAttribute("a", 2);
	request.setAttribute("a", 3);
	pageContext.setAttribute("a", 4);
	//같은 이름으로 키를 저장하는 일은 있어서는 안된다.
	//만약에
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	${a}<br>
</body>
</html>

 

'웹 프로그래밍 > JSP' 카테고리의 다른 글

[JSP] Annotation 및 xml 설정  (0) 2023.10.19
[JSP] JSTL( 조건문, 반복문 등 )  (0) 2023.10.19
[JSP] Cookie  (0) 2023.10.18
[JSP] tomcat 저장공간 Application, Session, Request, Page  (2) 2023.10.18
[JSP] forward, redirect  (0) 2023.10.18