日期:2014-05-16  浏览次数:20361 次

jsp中使用spring中的bean
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>

<body>
<%

ApplicationContext  ctx  =  WebApplicationContextUtils.getWebApplicationContext(getServletContext());

com.demo.service.UserService userService=(com.demo.service.UserService) ctx.getBean("userService");

System.out.println("------------->"+userService.getMessage());

%>
</body>