码迷,mamicode.com
首页 > 编程语言 > 详细

JSP访问Spring中的bean

时间:2014-10-28 17:24:22      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   os   ar   java   for   

JSP访问Spring中的bean

 

 

 

<%@page import="com.sai.comment.po.TSdComment"%>
<%@page import="com.sai.comment.service.CommentService"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="org.springframework.web.context.support.*"%>
<%@page import="org.springframework.context.*"%>
<%@page import="java.util.List"%>
<%@page import="org.springframework.web.context.support.*"%>
<%@page import="org.springframework.context.*"%>
<%@page import="com.sai.comment.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Lnua platform spy page</title>
</head>
<body>
    <%!private CommentService commentService;

    @Override
    public void init() {
        ApplicationContext ctx = WebApplicationContextUtils
                .getWebApplicationContext(getServletContext());
        commentService = (CommentService) ctx.getBean("commentServiceImpl");
    }%>
    <%
        try {
            String commentId = request.getParameter("commentId");
            TSdComment comment = commentService.findById(commentId);
            out.println(comment.getUser().getUserName());
            out.println(comment.getCreateTime());
            out.println(comment.getCommentContext());
            out.println(comment.getCommentId());
        } catch (Exception e) {
            e.printStackTrace();
            out.print("系统繁忙");
        }
    %>

</body>
</html>

 

JSP访问Spring中的bean

标签:style   blog   http   io   color   os   ar   java   for   

原文地址:http://www.cnblogs.com/mjorcen/p/4056904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!