Struts2:访问或添加request/session/application属性

Struts2访问request,session,application的四种方式 NULL 博文链接:https://aimilin6688.iteye.com/blog/1279546 立即下载

Structs2为了避免你直接访问servlet API ,它对request/session/application 这三个范围进行了封装,可以通过ActionContext对象获取

public String execute() throws UnsupportedEncodingException
{
    ActionContext ctx = ActionContext.getContext();
    ctx.getApplication().put("app", "应用范围");    //往ServletContext里放入app
    ctx.getSession().put("ses", "session范围");   //往session里放入ses
    ctx.put("req", "request范围");                //往request里放入req

    return "success";
}

JSP:
<body>
${applicationScope.app}<br>
${sessionScope.ses}<br>
${requestScope.req}<br>
</body>

如果一定想要获得request/session/application对象:
可以通过ServletActionContext类直接获取:

public String execute() throws UnsupportedEncodingException
{
//      ActionContext ctx = ActionContext.getContext();
//      ctx.getApplication().put("app", "应用范围");    //往ServletContext里放入app
//      ctx.getSession().put("ses", "session范围");   //往session里放入ses
//      ctx.put("req", "request范围");                //往request里放入req

    HttpServletRequest request = ServletActionContext.getRequest();             //request
    ServletContext servletContext = ServletActionContext.getServletContext();   //application 
    request.setAttribute("req", "request请求范围属性");
    servletContext.setAttribute("app", "app范围属性");
    request.getSession().setAttribute("ses", "会话范围属性");;

    return "success";
}

注:如果仅仅只是需要访问和添加,那么我们不需要获得对象, 用第一种即可。

北斗导航:提高RTK定位精度的GIS应用 其中,RTK(Real-Time Kinematic)定位技术是一种实时差分定位技术,通过利用基准站的观测数据来对移动站的测量值进行差分处理,以提高定位精度。差分处理的关键是基准站的观测数据,基准站通过全球定位系统(如北斗导航系统)获取卫星信号并记录观测数据。通过使用RTK定位技术,结合北斗导航系统的观测数据和差分处理,可以实现高精度的定位结果。我们将介绍RTK定位的原理、使用北斗导航系统进行RTK定位的步骤,以及如何将定位结果与GIS数据进行集成和可视化展示。步骤1:设置基准站和移动站。 阅读详情

相关推荐

用LTspice仿真Buck电路输出电容:从参数计算到波形优化的全流程演示

本文详细介绍了使用LTspice仿真Buck电路输出电容的全流程,从理论计算到波形优化。通过解析关键参数如纹波电压、瞬态响应和ESR,结合工程计算方法和LTspice仿真技巧,帮助工程师优化Buck电路设计,解决输出纹波过大和瞬态响应不佳的问题。

night的博客 851

struts2小结1

Struts2小结1                                                                                                        作者:卢海 一、struts1 和struts2的区别 struts2每次访问一个action时都会new一个新的对象出来,不会出现线程同步问题struts1每次初始...

luhai1992的专栏 194

Silvaco TCAD仿真4——DeckBuild实战:从示例库到自定义设计

本文详细介绍了Silvaco TCAD仿真工具DeckBuild的实战应用,从示例库的使用到自定义设计的全过程。通过具体案例和参数修改技巧,帮助用户快速掌握TCAD仿真技术,提升半导体器件设计的效率和精度。特别适合需要从基础入门到进阶操作的工程师和研究人员。

weixin_29284657的博客 434

Struts2的请求访问方式

Struts2的请求访问方式 问题:以上的代码,每一个请求,就对应一个,那么100个请求,就要配置100个。 这样配置很麻烦。 想法:能不能就使用一个接收同一个包所有的请求。 答:是可以的。==有两种方式实现。== 1. 通配符 2. 动态方法调用 动态方法的调用要注意ico优化 也就是地址栏的访问路径要简洁 使用*通配符实现(推荐使用) action的name属性可...

Kato_op的博客 1953

【Linux】实际项目应该如何完成?--安防监控系统项目的总结

到目前为止我也做个5、6个嵌入式项目,但以往都是从零开始自己做,也就是毫无计划,想到那里做那里,有想法就会去实现,就这样导致我碰到了很多坑,也消耗了我许多时间,当然,不是说这样不好,因为在其中我也得到了一个很好的锻炼与练习,但是这不适用于在工作中去这样做。...

修成真的博客 6727

高通Camera HAL3调试实战:如何用camxoverridesettings.txt高效抓取日志与dump图像数据

本文深入探讨了高通Camera HAL3调试中camxoverridesettings.txt文件的高效应用,重点介绍了如何通过该文件精准控制日志输出级别与dump图像数据,帮助开发者快速定位移动影像系统中的问题。文章详细解析了日志分级配置、图像数据捕获技巧及典型问题排查流程,为高通Camera HAL3项目开发提供了实用技术点。

weixin_30315905的博客 861

Struts2的Action中方法的几种访问方式

在Struts2中方法调用概括起来主要有以下几种形式:沿用上篇文章关于OGNL表达式的程序 1、指定Action的method属性访问 先在Action中再添加一个方法: public String success(){ System.out.println("方法为:"+"success"); return SUCCESS; } <!-- 第一种访问方式 http:

实践出真知 1万+

解读区块链在制药和物流管理中具备的优势

供应链透明度是建立药品弹性供应链的关键,如何更好地促进端到端的透明度,促进合作伙伴和消费者之间的信任度是当前医药和物流行业高管们关注的话题,区块链技术可以很好的帮助他们。 链集市 · 让区块链落地更简单 《区块链行业观察》专栏·第 31 篇 作者丨Shams Rahman 图片丨来源于网络 作者介绍:本文作者为Shams Rahman教授,是RMIT大学商业IT和物流学院的供应链管理教授、研究与创新部门副主任。本文中文版本由链集市团队编译整理,英文版权归原作者所有,中文转载请联系编译。 新冠肺炎疫情的爆发

CECBC的博客 623

Struts2框架之application、Request、Response、paramaters、Session实现及理解(案例驱动)

【案例】、请用struts2开源框架实现如下功能: 注解:下文中所提及的源目录文件,为struts源代码下载文件(本文用的代码为:struts-2.3.15.1)后,\struts-2.3.15.1\apps\struts2-blank.war项目解压的文件 步骤一:创建一个Web工程(struts2--2) 步骤二:将原生态的struts中的jar包(\struts2-blank\

zhongwen7710的专栏 1347

深度学习模型轻量化方法之【量化】

量化虽然有着硬件友好和功效提升的特点,但它也引入了模型性能的折衷。因此,设计有效的量化策略需要在模型大小、性能以及运算速度之间做出平衡。随着深度学习算法和硬件加速技术的快速发展,量化方法在使深度网络轻量化和提高部署效率方面持续发挥着重要作用。

m0_73916791的博客 2847

YOLO11改进-模块-引入多尺度差异融合模块MDFM

MDFM主要用于融合双时相图像特征并生成带有丰富上下文信息的差异特征,其过程包含以下步骤:1. 特征提取与差异特征生成首先从双时相图像中提取特征f1和f2,然后将f1和f2进行像素级别的相减,再对相减结果取绝对值,最后通过一个3x3的卷积操作得到Di。2. 多尺度特征融合(MSFF)接着利用多尺度特征学习机制来增强特征融合效果。该机制通过不同核大小的卷积构建多尺度融合过程,具体是通过一个名为 MSFF 单元来实现的。

qq_64693987的博客 4379

Struts2获取request,session,application的几种方式

request,session,application在正常使用时,在会话中传递数据的方式都是通过key-value的形式传递,因此,我们可以将它们看做Map,Struts2为我们提供了多种获取它们的方法; 通过ActionContext获取得到 public class TestAction1 extends ActionSupport { //初始化三个同名ma...

Struts2 240

Vue2 - 详细实现接入使用海康威视监控云端显示及控制功能,网站集成安装海康监控及实时监控显示、回放、放大缩小画面、视频画面截图、截屏抓拍、摄像头控制,实时推流及播放器解决延迟卡顿等问题(详细代码)

vue2,nuxt2,海康威视,海康监控,摄像头监控,vue对接海康处理接口认证规则,监控实时预览和回放功能,海康api接口,安全认证,海康开放平台,官方文档,播放海康摄像头的监控视频,海康实时监控播放详细步骤,web,黑屏,特别卡不流畅怎么办,解决无法推流,录像,连接不上,vue,海康,vue海康视频监控,海康开放平台,实时监控画面,海康插件,视频播放,回放,视频流地址,取流协议,视频sdk播放,hik,rtsp,rtmp,hls,ws,网站,网页,h5页面,后台管理系统,vue2对接海康监控设备,无法连

🏆 前端领域优质创作者 8245

struts2教程:13、访问或添加request/session/application属性

访问或添加request/session/application属性 struts2避免了直接访问servletAPI,所以没法获取request/session/application对象,但对他们进行了封装。 public String scope() throws Exception{    ActionContextctx = ActionContext.getContext();

cheney521的专栏 577

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

深度学习工具包 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")

struts2添加和访问request、session、application属性

struts2添加request、session、application属性 第一种方法: ActionContext ctx = ActionContext.getContext(); ctx.put("r1", list);//向request中添加属性 ctx.getSession().put("s1",list);//向session中添加属性 ctx.getApplic

hebiao100的专栏 2620

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

struts2中访问和添加Application、session以及request属性

一、访问或添加Application、session、request属性 《一》方式一 HelloWorldAction类中添加如下代码 //此方法适用于仅对Application、session、request对象添加属性值 public String execute(){ //访问或添加Application、session、request属性

幽林孤狼 524

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

【Struts2学习笔记(8)】访问或添加request/session/application属性获取HttpServletRequest / HttpSession / ServletContex

(1)访问或添加request/session/application属性 public String scope() throws Exception{ ActionContext ctx = ActionContext.getContext(); ctx.getApplication().put("app", "应用范围");//往ServletContext里放入app

徐刘根的博客 1707

Struts2 学习总结(三):Struts2在action中访问request,application,session对象的方式

接下来介绍Struts2中访问request,application,session对象的方式 在上面介绍了通过action访问用户输入,从而替代了访问HTTP Servlet Request,实现了与web层的解耦,但在某些特殊场景中,action中需要访问这些对象。Struts提供了多种方式访问这些对象,可以将这些方式大体分为两类: 与Servlet API解耦的方式和与Servlet A...

知且行的博客 1033

Struts2访问和添加Application、request、session属性介绍

向Application、request、session添加属性值 ActionContext ac=ActionContext.getContext(); //获取ActionContext ac.getApplication().put("app",”application范围“); ac.getSession().put("ses",”session范围“); ac.put("req",”...

专注Java后端技术干货、项目源码总结分享,期待您的关注。 279

Struts2 访问request session application对象

Struts2提供了了多种方式来访问上述的三种现象,归结起来,可以划分为两大类:与Servlet API 解耦的访问方式和与Servlet API耦合的访问方式。 一. 与Servlet API 解耦的访问方式     为了避免与Servlet API 耦合在一起,方便Action类做单元测试,Struts2对HttpServletRequest,HttpSession和Servlet

qq_36074113的博客 494

Struts2访问request、session、application对象

一、与Servelt API解耦访问方式  为了避免与Servlet API耦合在一起,方便Action类做单元测试,Struts 2对HttpServletRequest、HttpSession和ServletContext进行了封装,构造了三个Map对象来替代这三种对象,在Action中,直接使用HttpServletRequest、HttpSession和ServletContext对应的

态度决定思路,思路决定出路!!! 595

复习struts2之访问或添加属性

在struts2的action中并没有使用到servletAPI ,所以在方法中无法得到request,session和application对象,但在开发中我们又经常需要用到这些对象,该怎么办呢? 实例1:(如仅仅只是访问或往三个范围中放入属性推荐使用下面这种方法) Action中 public String execute(){ ActionContext ctx = ActionCon

1316

struts2示例代码-访问或者添加application、session、request等几个属性

有的时候servlet里传值需要session等属性,但是在struts2中怎么就可以用这些属性呢,就看下边的代码就行了 第一种方法: public String execute(){ ActionContext act=ActionContext.getContext()...

chengmeihu6937的博客 99

Struts 2 访问session request application 对象的方式

Struts2提供了了多种方式来访问上述的三种现象,归结起来,可以划分为两大类:与Servlet API 解耦的访问方式和与Servlet API耦合的访问方式。 一. 与Servlet API 解耦的访问方式     为了避免与Servlet API 耦合在一起,方便Action类做单元测试,Struts2对HttpServletRequest,HttpSession和S

qq_36074042的博客 339

struts2中,在request/session/application中访问或添加属性

第一种: public String scope() throws Exception{    ActionContext ctx = ActionContext.getContext();    ctx.getApplication().put("app", "应用范围");//往ServletContext里放入app    ctx.getSession().put("ses", "s

u012805511的专栏 776

Struts2 访问request session application对象 。

Struts2提供了了多种方式来访问上述的三种现象,归结起来,可以划分为两大类:与Servlet API 解耦的访问方式和与Servlet API耦合的访问方式。 一. 与Servlet API 解耦的访问方式     为了避免与Servlet API 耦合在一起,方便Action类做单元测试,Struts2对HttpServletRequest,HttpSession和S

weixin_36024620的博客 278
上一篇: Struts2:自定义类型转换器
下一篇: Struts2:文件上传
minGW_Lee
博客等级 码龄11年 19粉丝 69原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值