自定义标签与spring注入

[url]http://tcrct.iteye.com/blog/258657[/url]

在以往,我们自定义一个标签时一般都是这样写的
public class Options extends TagSupport {

public int doEndTag() throws JspTagException {
JspWriter out = pageContext.getOut(); // 重要
StringBuffer sb = new StringBuffer();
try {

sb.append(createHtml());

out.print(sb.toString());

} catch (Exception e) {
e.printStackTrace();
}

return EVAL_PAGE; // 表示处理完标签后继续执行以下的JSP网页
// return SKIP_PAGE; //表示不处理接下来的JSP网页
}

public string createHtml(){
...........
}

}

但是如果要用到spring注入一个bean去调用DAO层时,在get时有值,但set时就会为null的,这个问题搞了我整整一天,上网查资料,试过两种方式的注入都是一样的。后来,再查资料时偶然发现这一个网址里写了解决的方法。[url]http://topic.csdn.net/u/20080716/11/92f124e3-b51d-4610-9cfe-744317726604.html[/url]。通过上面的提示得出答案,故要将以上的代码改写成这样:
public class Options extends RequestContextAwareTag{

public int doStartTagInternal() throws JspTagException {
JspWriter out = pageContext.getOut(); // 重要
StringBuffer sb = new StringBuffer();
try {

sb.append(createHtml());

out.print(sb.toString());

} catch (Exception e) {
e.printStackTrace();
}

return EVAL_PAGE; // 表示处理完标签后继续执行以下的JSP网页
// return SKIP_PAGE; //表示不处理接下来的JSP网页
}

public string createHtml(){
...........
JdbcTemplate jdbc = (JdbcTemplate)this.getRequestContext().getWebApplicationContext().getBean("jdbcTemplate");
...............
}

}

此处的jdbcTemplate是spring里指定的bean名字,即ID名,在这里这样写,就不需要注入到自定义的类里,直接取一个已经存在的bean。注意继承的类及必须要实现的方法和上面的那一个不一样的。
深入解析:如何在Visual Studio中高效编译libredwg与libdxfrw 本文详细介绍了在Visual Studio中高效编译libredwg与libdxfrw的完整流程,包括环境配置、源码获取、CMake技巧及常见错误解决方案。针对CAD开发者,提供了从基础编译到项目集成的实用指南,帮助快速处理DWG/DXF文件,提升开发效率。 阅读详情

相关推荐

自动驾驶入门到进阶完整指南:感知、预测、规划、端到端、仿真测评与场景挖掘全解析

对小白来说,不建议一开始直接冲端到端大模型。先学数据和坐标系:否则所有结果都看不懂。再学 LiDAR 3D 检测:最容易建立空间感。再学 BEV/多相机感知:这是当前主流。再学轨迹预测:理解交互和多模态。再学规划控制:理解车为什么这样开。再学仿真和闭环评测:理解 open-loop 和 closed-loop 差异。最后学端到端/VLM/VLA:这时候你才知道它到底替代了哪些模块。贯穿始终学习场景挖掘和安全测评:这是工业界最核心的能力之一。

u013250861的博客 410

spring注解开发定义bean学习

spring注解开发定义bean学习

weixin_58057048的博客 542

从零构建腾讯滑块验证码破解引擎:逆向工程与实战对抗

本文深入解析腾讯滑块验证码(原天御验证码)的防护机制,包括环境感知层、行为分析层和验证决策层的核心技术。通过JSVMP虚拟机保护、轨迹验证算法和动态加密体系,腾讯验证码实现了高效的人机识别。文章还提供了安全研究实践指南,涵盖环境模拟和验证码识别方案,并探讨了防御对抗的演进趋势与合规研究建议。

rl6adventurer的博客 839

Spring自定义对象的注入配置

以上文章介绍的方法或方式,都是注入基本数据类型例如String,int等等,本例将介绍自定义对象的注入方式的配置。 【转载使用,请注明出处:http://blog.csdn.net/mahoking】 操作步骤: 1、 创建Topic对象。 public class Topic { /**内容*/ private String context; public String get

HOKING的专栏 3769

【数据分析】比较SparCC、Pearson和Spearman相关性估计方法在合成组学数据上的表现

【数据分析】比较SparCC、Pearson和Spearman相关性估计方法在合成组学数据上的表现

专注生信领域 675

【WorkBuddy专栏52】Codex与WorkBuddy生态适配、用户争夺与未来走向(下)

【WorkBuddy专栏52】Codex与WorkBuddy在中国大陆的发展——生态适配、用户争夺与未来走向(下)

AI人人懂 705

Spring 自定义DI注入

1.依赖注入: IOC的作用:降低程序之间的耦合(依赖关系) 概念:依赖关系的管理交给spring维护,在当前类需要用到其他类的对象,由spring为我们提供,只需在配置文件中说明关系的维护; 2.问题 平时使用spring 框架的时候,我们知道从前端传递参数,后端可以用@RequestBody,来创建并将参数注入到对象当中,突然某一时刻,前端不传递参数,但是我们想拿一个对象使用,比如 用户的登录信息。前端只传递了一个...

ZPBLSing的博客 243

SAP 实例解析分期付款配置及应用

SAP系统的付款条件支持分期付款功能,其奥妙之处就在于需要定义一个母条款和一个子条款,其中,母条款需要标识“分期付款”。 首先,定义分期付款的母条款OBB8:             然后,定义子条款(即分期付款的具体方式)OBB9:   由上图可以看出,分期付款的配置还是很强大的,针对每次付款,都可以进行第二层次付款条件的设置。   然后,我们做一笔发票,

heng0757的专栏 1万+

spring 自定义注解,动态注入Bean

文章目录背景ImportBeanDefinitionRegistrar1.定义注解2.启动注解3.实现接口4.扫描器5.使用Bean6.使用注解7.启动类总结 背景 @Configuration 注解的类会被spring自动的扫描注入为Bean,如果想自己定义一个注解实现相同的功能如何来实现 ImportBeanDefinitionRegistrar 熟悉spring源码的同学应该知道,注册bean实际上就是注册beandefinition 这个类刚好有接口可以实现 default void regis

csdn问鼎 5812

科研项目数据抓取:Python爬虫实现与分析

本文详细介绍了如何使用Python爬虫抓取科研项目的数据,涵盖了从目标数据源选择到数据存储与分析的整个过程。通过使用。

2201_76125261的博客 1715

论文阅读 AIED 2024 Coding with AI: How Are Tools Like ChatGPT Being Used by Students in Foundational Pro

该论文题为《Coding with AI: How Are Tools Like ChatGPT Being Used by Students in Foundational Programming Courses》,由美国犹他州立大学的 Aashish Ghimire 与 John Edwards 共同撰写,发表于人工智能与教育领域顶级会议。

CSPhD-winston的博客 312

在struts 自定义标签中注入spring bean

如题: 由于struts自定义标签不在spring 的管理范围内,所以没有办法进行spring的正常注入 解决方法: WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext()); Use

萧若寒 1131

RDKit | 基于Murcko骨架聚类化合物库

化合物多样性评估 一种方法是使用合适的指纹技术将化合物矢量化并评估他们之间的距离。这种方法经常被使用,但是对于人类很难直观地理解化合物之间的距离。 基于Murcko骨架,分子大致聚集在化合物骨架中,并且每个簇中的顶部化合物都作为候选化合物。此方法非常符合人类的直觉,因此可以预期人将通过查看候选化合物列表来自动缩小化合物的范围。 Murcko骨架 Mur...

DrugOne 3772

自定义标签Spring注入的问题

自定义标签使用spring 的注入@Resource 或@Autoware来注入bean,可能得不到bean,或者页面在使用标签时报没能绑定标签对应的处理类, 这个问题可以用如下方法得到bean,      WebApplicationContext web = WebApplicationContextUtils.getRequiredWebApplicationContext(this.

移动空间678 1575

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

聊聊自定义SPI如何使用自定义标签注入到spring容器中

前言 之前我们聊过自定义的SPI如何与spring进行整合,今天我们就来聊下如何通过自定义标签将spi对象注入到spring容器中 实现套路 1、自定义xsd 示例: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframewo

kingwinstar的博客 699

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

RequestContextAwareTag 自定义标签解决 TagSupport 不能进行 spring 的 bean 注入问题

在进行自定义标签时,使用TagSupport,不能进行 spring 的 bean 注入,当然,我们可以自己实现,但是 spring 框架不可能没有考虑到这一点,因此不使用TagSupport,而使用 spring 框架提供的 RequestContextAwareTag,进行自定义标签的开发,RequestContextAwareTag 实际上继承了TagSupport,对 TagSupport 进行了扩展,扩展后就可以通过 spring 的 RequestContext 获取 spring 的 b...

悟世君子的博客 795

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

自定义标签与spring注入报空

在自定义标签中注入spring对象报空   参考链接:http://tcrct.iteye.com/blog/258657

zhang284021445的专栏 157

自己设计一个的轻量级的RPC框架--客户端Spring 自定义标签和自定义注入bean

自己设计一个的轻量级的RPC框架--客户端Spring 自定义标签和自定义注入bean前言Spring 自定义标签spring-rpcClient.xsdspring.schemasspring.handlersRPCClientNameHandler自定义注入bean解释一下 前言 尝试后端调用服务要和普通controller一样,所以普通的注入service接口以及不适用于当前场景。因为调用接...

a294634473的博客 689

spring整合velocity使用directive自定义标签类,引用service层实例无法注解注入问题

配置velocity自定标签。 调试时发现自定义标签类由spring依赖注入的实例service方法为null。 断点跟踪自定义标签继承类Directive的init方法。发现@Resource、@Autowired注入无效的原因是用户自定义标签类的实例由反射生成,不由spring容器创建。 org.apache.velocity.runtime.directive.Directive.init() -&...

折戟沉沙嗜血柔情 934

拓展Spring-xml标签,自定义个性化标签注入到Spring容器中

拓展Spring-xml标签,自定义个性化标签背景概述实践创建一个xsd文件创建一个bean类创建spring表述文件Handler处理类标签解析器在配置中添加bean测试从容器中取到bean 背景 最近看一个项目,在spirng配置文件中,引用了非正常标签,上面配置几个参数,启动后就可以在别的bean中注入了 于是就引发了我的好奇心,决定一探究竟 概述 spring在启动的时候,读取配置文件的...

习惯了想你的博客 707

freemark自定义标签类 注入spring 的service

package com.orchid.system.util; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAwar...

又是一天 239

JSP自定义标签的spring注入

package com.financegene.struts.tag.views; import java.io.IOException; import java.util.List; import javax.servlet.ServletContext; import javax.servlet.jsp.JspException; import javax.servlet.j

oqq2012123456789111的专栏 555

spring篇-(spring自定义标签,属性)

spring自定义标签初始化项目基于spring,实现自定义标签扩展自定义标签,添加对象属性的注入 初始化项目 项目使用maven构建,项目结构如下 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" x

qq_42413011的博客 624
上一篇: Spring Web Flow 2.0 入门详解
下一篇: jquery.i18n.properties使用小记
不净之心
博客等级 码龄20年 50粉丝 1626原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值