JSP访问Spring中的bean
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>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。