java struts2 获取项目路径

struts2文件下载/绝对路径+相对路径 http://blog.csdn.net/love_xiolan/article/details/54945859 博文地址 此代码,下载后,倒入到eclipse中即可使用.. 立即下载

java:

 

getServletContext().getRealPath("/")

 

struts2:

 

ResourceBundle resource = ResourceBundle.getBundle("voicefileInfo");
               
ActionContext ac = ActionContext.getContext(); 
ServletContext sc = (ServletContext) ac.get(ServletActionContext.SERVLET_CONTEXT); 
String LogDir = sc.getRealPath("/").concat(resource.getString("LogDir"));

 

都可利用severlet中的getRealPath("/")方法

windows linux 下,获取java项目绝对路径的方法 windows linux 下,获取java项目绝对路径的方法,struts2设置了struts.multipart.saveDir后会在根目录建立文件夹,这样会涉及linux下的权限问题 立即下载

相关推荐

OpenFOAM算例文件结构深度解析:以cavity案例为例教你读懂每个文件夹的作用

本文以OpenFOAM经典cavity案例为例,深度解析CFD算例文件结构。详细阐述了0、constant、system三个核心目录的作用:0存放初始与边界条件,constant定义物理属性和网格,system控制求解策略。通过剖析关键文件,帮助用户理解每个参数的意义,掌握从读懂到定制算例的能力,为高效使用这一开源CFD工具奠定坚实基础。

beer8的博客 255

在struts的action 中获取项目路径

  在struts的action 中获取项目路径   //绝对路径 String abspathString=ServletActionContext.getServletContext().getRealPath(""); //相对路径 String root = ServletActionContext.getRequest().getContextPath();   ...

wuhao1014的专栏 670

10X Genomics数据实战:手把手教你用Seurat处理单细胞PBMC数据(附完整代码)

本文详细介绍了如何使用Seurat处理10X Genomics的单细胞PBMC数据,从数据获取、质控到降维分析和细胞分群的全流程。通过实战代码演示,帮助研究者掌握单细胞RNA测序数据分析的核心技术,提升对细胞异质性的理解。

weixin_29053577的博客 266

spring boot 加载资源路径配置和classpath问题

1、spring boot默认加载文件的路径: /META-INF/resources/ /resources/ /static/ /public/ 我们也可以从spring boot源码也可以看到:private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:

Just Play的博客 3万+

Uncertainty-Aware Mean Teacher(UA-MT)

本文提出了一种新的基于不确定性的半监督学习框架(UA-MT),通过额外利用未标记的数据从3D MR图像中分割左心房。具体地说,本文建立了一个教师模型和一个学生模型,学生模型通过最小化标注数据上的分割监督损失和所有输入数据上的与教师模型预测输出的一致性损失进行优化。如果没有未标记输入中的注释,教师模型的预测目标可能不可靠且有噪声。:在估计不确定性 U 的指导下,我们过滤掉相对不可靠**(高不确定性),整个体积** U 的不确定性**是 {u} ∈ RH×W ×D。过滤掉高不确定性的,也就是熵大于某个值的。

Alexa_的博客 1883

Android 车载开发深度解析:CarPropertyManager 核心机制与实践指南

摘要: Android Automotive OS中,CarPropertyManager作为车载信息娱乐系统的核心组件,连接应用层与车辆硬件(如车速、油量等),其架构基于分层设计(App→CarAPI→VHAL→ECU),采用发布-订阅模式实现高效数据通信。通过HIDL/AIDL跨进程交互及共享内存优化,延迟可降至2ms以下。安全机制包括分级权限控制(VISIBLE/PROTECTED/SYSTEM_RESTRICTED)和HMAC防篡改。开发时需注意监听器生命周期管理、事件合并降负载及低功耗适配。

郑伟强dev的专栏 352

Struts2获取项目物理路径

因为工作中涉及文件操作。需要获取物理路径。 ActionContextac=ActionContext.getContext(); ServletContextsc=(ServletContext)ac.get(ServletActionContext.SERVLET_CONTEXT); Stringpath=sc.getRealPath("/"); ...

冷峰的空间 159

智能预测性维护AI系统实战效率提升:AI应用架构师的技巧分享

在工业领域,预测性维护(Predictive Maintenance, PdM)是降低停机损失、优化维护成本的关键手段。然而,现有系统往往面临三大效率瓶颈数据处理延迟:工业设备产生的海量实时数据(如传感器、PLC)需传输至云端处理,导致预警滞后;模型推理效率:复杂深度学习模型(如ResNet、Transformer)在边缘设备上推理时间长,无法满足实时要求;落地集成困难:与企业现有ERP、MES、SCADA系统对接繁琐,导致“模型好用但业务不用”的尴尬。本文从架构、数据、模型、落地架构设计。

AI天才研究院 751

struts2获得项目路径

[code="java"] ActionContext ac = ActionContext.getContext(); ServletContext sc = (ServletContext) ac.get(ServletActionContext.SERVLET_CONTEXT); String path = sc.getRealPath("/"); [/code]

黑色雨滴 296

30、强化学习求解车辆路径问题

本文探讨了强化学习在车辆路径问题(VRP)中的应用,详细介绍了强化学习的基本原理和主要算法,并分析了其在解决VRP中的关键步骤和优化策略。文章还通过实验结果和实际案例展示了强化学习在求解VRP中的显著优势与未来发展方向。

s4t5u6v的博客 124

什么是 AI Agent?它和直接调用大模型 API 有什么区别?

什么是 AI Agent?它和直接调用大模型 API 有什么区别?

我哎GIS博客 6515

struts2中获取目录的真实路径

String templatePath = ServletActionContext.getServletContext().getRealPath("/template/identificationtemplate"); String paperPath = ServletActionContext.getServletContext().getRealPath("/template/iden

大道至简 分而治之 1280

yolov5运行detect.py之后卡住了?没后续,没结果,没报错,怎么办?如何解决?

🏆 本文收录于《全栈Bug调优(实战版)》专栏,致力于分享我在项目实战过程中遇到的各类Bug及其原因,并提供切实有效的解决方案。无论你是初学者还是经验丰富的开发者,本文将为你指引出一条更高效的Bug修复之路,助你早日登顶,迈向财富自由的梦想🚀!同时,欢迎大家关注、收藏、订阅本专栏,更多精彩内容正在持续更新中。让我们一起进步,Up!Up!Up!    备注: 部分问题/难题源自互联网,经过精心筛选和整理,结合数位十多年大厂实战经验资深大佬经验总结所得,数条可行方案供所需之人参考。

**My Coding Family** 1118

java action 获取项目路径_struts2获取工程根目录

最近学习struts2的文件上传和下载,由于书中的方法ServletActionContext.getRequest().getRealPath("/")已经过时,所以寻找了其它获取工程根目录方法。在尝试过程中曾试过使用相对路径方法,结果相对路径为eclipse的根目录,所以此方法行不通。由于工程路径封装在了Servlet的ServletContext中,我们可以在Action中直接访问Servl...

weixin_39732991的博客 405

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

struts2之路径问题

1.费话不说,我的项目名称为zzcz99,先看代码:   String baseContextPath = ServletActionContext.getRequest().getContextPath() + "/"; String baseFullCxtPath = ServletActionContext.getServletContext().getRealPath("/")...

Arthur0088的专栏 198

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

java中获取项目中文件,java项目中获取路径以及读写文件

在项目中一般都会遇到文件的读写,一般有两个问题要进行处理1路径问题2读写问题路径的解决方法路径之间的连接"//"="\\"="/"eg1:D盘下面file文件夹里面的1.txtpath="D://file//1.txt"path="D:/file/1.txt"path="D:\\file\\1.txt"这三种都可以1绝对路径(坚决不推荐使用)就是从电脑的根目录开始C盘D盘,详情参考eg12相对路径...

weixin_42309311的博客 859

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

java获取访问路径、域名、项目名、请求入参

废话不多说(这句不是废话吗&gt;&gt;),直接提出可以运行的类,你放到一个web项目访问下就知道了。     //测试页面-跳转到输入数据的form表单 public String test1(){ ActionContext ctx = ActionContext.getContext();           HttpServletRequest r...

weixin_34082789的博客 226

java 在linux获取项目路径_windows linux 下,获取java项目绝对路径的方法

struts2设置了struts.multipart.saveDir后会在根目录建立文件夹,这样会涉及linux下的权限问题,最好不要设置,使用struts默认需要使用路径时,用下面的方法取得项目根目录的绝对路径(Tools为方法类)public static String getRootPath() {String classPath = Tools.class.getClassLoader()...

weixin_39610785的博客 2468

JAVA中各种路径获取

1 在SSH各个层次获得项目根目录 REQUEST 等 [code="java"] 1.System.out.println(ServletActionContext.getServletContext().getRealPath("/")); 2.ystem.out.println(Struts2Utils.getParameter("loginName")); Sys...

zhourrr1234的专栏 142

javaEE struts2中的路径问题

艰辛地学了3个月java,最近在做项目了,在期间遇到很多问题让我进步很多,老师说软件是改出来的而不是写出来的,现在我有那么一点点体味了! 废话不说那么多了,说说路径问题吧,我们知道路径有绝对路径和相对路径,在开发的过程中我建议使用绝对路径,因为使用绝对路径后不会出现因为文件夹相对的位置发生而失去一些效果的呈现,我总结了一下有以下几种情况: 1、在访问应用时,我们没有必要去把请求的acti...

万物皆字节 1380

java rootpath_windows linux 下,获取java项目绝对路径的方法 | 学步园

struts2设置了struts.multipart.saveDir后会在根目录建立文件夹,这样会涉及linux下的权限问题,最好不要设置,使用struts默认需要使用路径时,用下面的方法取得项目根目录的绝对路径(Tools为方法类)public static String getRootPath() {String classPath = Tools.class.getClassLoader()...

weixin_31421601的博客 270

java路径问题总结

1 在SSH各个层次获得项目根目录 REQUEST 等 [code="java"] System.out.println(ServletActionContext.getServletContext().getRealPath("/")); System.out.println(Struts2Utils.getParameter("loginName")); [/code] 利用了STRU...

Deans 144

struts2上传多张图片的方法

原文地址 package eao; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import javax.servlet....

一只不知疲倦的学习猿 1202

Java Web(13)struts2 file upload 临时文件命名问题

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33828101的博客 166
上一篇: getResourceAsStream
下一篇: struts2 文件流, 文件输出到浏览器 文件下载
ctrl_shift_del
博客等级 码龄16年 6粉丝 7原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址