


내장객체의 표현식이 생략되었을 때 규칙.
1. pageScope영역에서 찾는다.
2. request > 3. session > 4. application
[영역이작은쪽부터]
예제
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <% request.setAttribute("userName", "김태형1"); session.setAttribute("userName", "김태형2"); application.setAttribute("userName", "김태형3"); session.setAttribute("userId", "V"); %> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <h1> <!-- 내장객체의 표현식이 생략되었을 때 규칙. 1. pageScope영역에서 찾는다. 2. request > 3. session > 4. application [영역이작은쪽부터] --> requestScope.userName : ${requestScope.userName}, ${userName}, <!-- 영역 생략가능 --> <%= request.getAttribute("userName") %> <br> sessionScope.userId : ${sessionScope.userId}, ${userId} <%= session.getAttribute("userId") %> <br> param.code : <%=request.getParameter("code") %>, ${param.code}<br> pageContext : <%= pageContext.getRequest().getServletContext().getContextPath() %><br> ${pageContext.request.requestURI}<br> ${pageContext.request.requestURL}<br> ${pageContext.request.contextPath}<br> </h1> <a href="view1.jsp">session페이지 확인</a> </body> </html>

view1.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> <h1> ${sessionScope.userId}, ${userId} </h1> </body> </html>





예제
test패키지 안의 자바클래스 product.java 생성
package test; import java.util.Arrays; //상품 정보를 가지는 beans 형식으로 정의 public class Product { // 상품 목록 private String[] productList = {"item1","item2","item3","item4","item5",}; // 테스트 변수 private int price = 100; private int amount = 1000; public String[] getProductList() { return productList; } public int getPrice() { return price; } public int getAmount() { return amount; } public String getDisplay() { return "price: "+ price + ", amount : " + amount; } @Override public String toString() { return "Product [productList=" + Arrays.toString(productList) + ", price=" + price + ", amount=" + amount + "]"; } }
productList.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> <jsp:useBean id="product" class="test.Product" scope="session"/> <%-- ${product} <br> --%> <%-- ${sessionScope.product} --%> <form action="selectProduct.jsp" method="post"> <select name="sel"> <% for(String item:product.getProductList()){ out.println("<option>"+item+"</option>"); } %> </select> <input type="submit" value="선택"> </form> </body> </html>
selectProduct.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> 1. 선택한 상품 : ${param.sel} <br> 2. 상품 설명 : ${product.display} <br> <!-- > display라는 변수는 없음 product.getDisplay() --> 3. 상품 : ${product.productList[0]} </body> </html>


'JAVA > Jsp&Servlet' 카테고리의 다른 글
[JSP] FileUpload (0) | 2020.12.24 |
---|---|
[JSP] JSTL - fmt (0) | 2020.12.23 |
[JSP] JSTL 설치 및 사용 / core <c:~> (0) | 2020.12.23 |
[JSP] mysql JDBC (0) | 2020.12.18 |
[JSP] session 기본 객체 (0) | 2020.12.18 |
[JSP] 쿠키처리를 위한 유틸리티 클래스 만들기 (0) | 2020.12.17 |
[JSP] 쿠키 (0) | 2020.12.17 |