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的更多相关文章

  1. Thymeleaf:访问Spring中的bean

    项目做了动静分离,即静态文件全部放在nginx中,动态文件在tomcat中,如何引用静态文件,我是这么做的,见下: 运行结果:

  2. Spring 中的bean 是线程安全的吗?

    结论: 不是线程安全的 Spring容器中的Bean是否线程安全,容器本身并没有提供Bean的线程安全策略,因此可以说Spring容器中的Bean本身不具备线程安全的特性,但是具体还是要结合具体sco ...

  3. 【Spring】Spring中的Bean - 5、Bean的装配方式(XML、注解(Annotation)、自动装配)

    Bean的装配方式 简单记录-Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)-Spring中的Bean 文章目录 Bean的装配方式 基于XML的装配 基于注解 ...

  4. Spring 中的 bean线程安全性分析

    首先:Spring 中的 bean不是线程安全的 Spring容器中的Bean是否线程安全,容器本身并没有提供Bean的线程安全策略,因此可以说Spring容器中的Bean本身不具备线程安全的特性,但 ...

  5. 传统javabean与spring中的bean的区别

    javabean已经没人用了 springbean可以说是javabean的发展, 但已经完全不是一回事儿了 用处不同:传统javabean更多地作为值传递参数,而spring中的bean用处几乎无处 ...

  6. 1.2(Spring学习笔记)Spring中的Bean

    一.<Bean>的属性及子元素 在1.1中我们对<Bean>有了初步的认识,了解了一些基本用法. 现在我们进一步理解<Bean>属性及子元素. 我们先来看下< ...

  7. spring扩展点之二:spring中关于bean初始化、销毁等使用汇总,ApplicationContextAware将ApplicationContext注入

    <spring扩展点之二:spring中关于bean初始化.销毁等使用汇总,ApplicationContextAware将ApplicationContext注入> <spring ...

  8. 第2章 Spring中的Bean

    2.1 Bean的配置 Bean本质是Java中的类.Spring可以被看做一个大型工厂,这个工厂的作用就是生产和管理Spring容器zho中的Bean.想在项目中使用这个工厂,就需要对Spring的 ...

  9. spring 中的 bean 是线程安全的吗?

    spring 中的 bean 是线程安全的吗? Spring 不保证 bean 的线程安全. 默认 spring 容器中的 bean 是单例的.当单例中存在竞态条件,即有线程安全问题.如下面的例子 计 ...

随机推荐

  1. 完美解决移动Web小于12px文字居中的问题

    前几天的一篇博文:移动Web单行文字垂直居中的问题,提到了移动web里小于12px的文字居中异常的问题,最后还是改为12px才近乎解决了问题.但是有时候或许并不是那么乐观,你并不能将原本定为10px的 ...

  2. 济南学习 Day 4 T1 am

    完美的序列(sequence)Time Limit:1000ms Memory Limit:64MB题目描述LYK 认为一个完美的序列要满足这样的条件:对于任意两个位置上的数都不相同.然而并不是所有的 ...

  3. HDU 5024 Wang Xifeng's Little Plot(枚举)

    题意:求一个图中只有一个90°拐点的路的最大长度. 分析:枚举每一个为'.'的点,求出以该点为拐点的八种路中的最大长度,再比较所有点,得出最大长度即可. 如上样例,这样是个90°的角... 注意:最多 ...

  4. 关于C++string的长度陷阱

    std::string s = ...; ..... assert(s.length() == strlen(s.c_str())); 一般认为这段代码是不会断言失败的,但是实际上这段代码可能是会断言 ...

  5. 使用JDBC向数据库中插入一条数据

    原谅我是初学者,这个方法写的很烂,以后不会改进,谢谢 /** * 通过JDBC向数据库中插入一条数据 1.Statement 用于执行SQL语句的对象 1.1 通过Connection 的 * cre ...

  6. OpenDaylight之openflowjava的编译

    最近因为工作需要开始研究opendaylight,首先需要的是编译项目. 因为项目代码都是在git.opendaylight.org上的,所以需要先安装git工具. 另因为opendaylight项目 ...

  7. javascript对象与实例

    var person=new Object(); var person2={}; 一切都是对象 person是Object的实例, 也是对象. 第二个person2也是如此,只不过它是采用字面量的方式 ...

  8. 【Qt】Qt之进程间通信(QProcess)【转】

    简述 前几节里,分享了进程通信的几种方式:Windows消息机制.Shared Memory(共享内存),本节讲解下关于进程通信的另外一种方式-QProcess. 简述 命令行参数启动 说明 实现 命 ...

  9. Ubuntu16.04.1 安装Redis-Cluster

    Redis在3.0版正式引入了集群这个特性.Redis集群是一个分布式(distributed).容错(fault-tolerant)的 Redis内存K/V服务, 集群可以使用的功能是普通单机 Re ...

  10. 重拾C,一天一点点_5

    switch(表达式){    case 整型常量表达式:语句序列    case 整型常量表达式:语句序列    default:语句序列} while(表达式)    语句 for(表达式1; 表 ...