본문 바로가기

JAVA/JSP & Servlet

익스프레션 언어(expression language) JavaBean 객체

ProductInfo.java

package el;

 

public class ProductInfo {

        private String name;

        private int value;

       

        public ProductInfo(){

              

        }

 

        public String getName() {

               return name;

        }

 

        public void setName(String name) {

               this.name = name;

        }

 

        public int getValue() {

               return value;

        }

 

        public void setValue(int value) {

               this.value = value;

        }

 

}

 

 

ProductInfo.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@page import="el.ProductInfo"%>   

 

<%

        ProductInfo product = new ProductInfo();

 

        product.setName("초코케이크 8");

        product.setValue(2000);

       

        request.setAttribute("product", product);

       

        RequestDispatcher dispather = request.getRequestDispatcher("ProductInfoView.jsp");

        dispather.forward(request, response);

%>

 

 

 

ProductInfoView.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>익스프레션 : 자바빈의 프로퍼티 출력</title>

</head>

<body>

 

상품명 : ${product.name }<br>

가격 : ${product.value }<br>

 

 

</body>

</html>