내용

글번호 599
작성자 heojk
작성일 2017-02-20 04:23:24
제목 Spring MVC를 사용하는 JSP 페이지에서 빈 가져오기 예
내용 Spring WebApplicationContext를 이용하면 JSP에서 스프링 빈을 사용할 수 있다.
<%@page import="kr.co.javaspecialist.board.model.service.impl.BoardCategoryService"%>
<%@page import="java.util.List"%>
<%@page import="kr.co.javaspecialist.board.model.vo.BoardCategory"%>
<%@page import="kr.co.javaspecialist.board.model.service.IBoardCategoryService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page contentType="text/html; charset=UTF-8" trimDirectiveWhitespaces="true" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%
	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
	IBoardCategoryService categoryService = wac.getBean(BoardCategoryService.class);
	List<BoardCategory> categoryList = categoryService.selectAllCategory();
	request.setAttribute("categoryList", categoryList);
%>