JAVA 关于图片上传的代码

【归纳总结】JavaEE之Fileupload——向服务器上传文件 一、如何向服务器上传一个本地图片? 首先,Fileupload的使用场景:比如说提交作业,更换头像。 需要一个form表单,表单有如下三个要求 input type = file method = post enctype=multipart/form-data @WebServlet("/upload") public class UploadServlet extends HttpServlet { protected void doPost(HttpServletRequest reque 阅读详情
private File file; 

private String fileFileName; 
private String picture; 
//都有getter 和 setter 

InputStream is = new FileInputStream(file); 
//引入一个IO流的输入流
String root = ServletActionContext.getRequest() 
.getRealPath("/bookpicture"); 
//通过REQUEST来得到相对地址,并在后面加上/bookpicture

File f = new File(root, this.getFileFileName()); 
//定义一个FILE文件,第一个参数是文件的路径,第二个是文件的名字

picture="."+"\\"+"bookpicture"+"\\"+this.getFileFileName();
//为PICTURE字符串赋值,/地址/文件名 
System.out.println 
("======picture====="+picture); 
//从控制台输出Picture

OutputStream os = new FileOutputStream(f); 
//第一个文件的输出流

byte[] buffer = new byte[1024];
//定义一个bufer的字符串,长度为1024
 
int len = 0; 
while ((len = is.read(buffer)) > 0) { 
//如果从制定文件中读取到的信息为结束就继续循环
os.write(buffer, 0, len); 
//将文件读出的内容写入到指定的文件中

}

package com;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import com.jspsmart.upload.*;



public class uploadfiles extends HttpServlet
{
	public void doGet(HttpServletRequest request,HttpServletResponse response)
					throws ServletException,IOException
	{
		//使用了一个第三方的组件,存放在web-inf/lib下
       		response.setContentType("text/html;charset=GB2312");
       	
       		//由于SmartUpload的初始化方法需要pageContext,所以我们在servlet中得到他
       		//为了得到pageConext要首先得到JspFactory的实例
       		//通过JspFactory的实例的getPageContext方法得到pageConext的实例
		JspFactory jf = null;
		
		//得到JspFactory的实例
		jf=JspFactory.getDefaultFactory();
				
		/*
		getPageContext(Servlet servlet, 
					   ServletRequest request, 
					   ServletResponse response, 
					   java.lang.String errorPageURL, 
					   boolean needsSession, 
					   int buffer, 
					   boolean autoflush)
       	*/       	
		PageContext pageContext=jf.getPageContext(this,request,response,null,true,8192,true);
		
		try
		{
			//实例化SmartUpload
			SmartUpload mySmartUpload=new SmartUpload();
			
			//初始化SmartUpload的实例,需要PageContext的实例
			mySmartUpload.initialize(pageContext);
			
			//设定最大上传的字节数,其实可以不进行设定,表示上传的文件没有大小限制
			//mySmartUpload.setTotalMaxFileSize(10000000);
			mySmartUpload.upload();
			
			//下面是单文件上传
			//上传的文件以com.jspsmart.upload.File 代表,如果文件名称重复,则进行覆盖
			com.jspsmart.upload.File file=mySmartUpload.getFiles().getFile(0);
			String upLoadFileName=file.getFileName();
			
			//调用com.jspsmart.upload.File实例的saveas的方法保存文件,此时的文件名即是
			//保存到服务器上的文件名
			file.saveAs("/upload/"+upLoadFileName);
			Request req = 
			Text t = .....;
			t.setUpload(upLoadFileName);
			t.set.....(req);
		}
		catch(SmartUploadException e)
		{
			System.out.println(e.getMessage());
		}

		
	
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException
	{
		doGet(request,response);
	}
}





        
Java实现Fast DFS图片上传(代码) 之前写了,linux上安装配置Fast DFS整合nginx,图片上传测试。 这里在写一下,Java实现Fast DFS图片上传。 开始: maven添加fastdfs相应的jar包 jar包下载地址:链接:https://pan.baidu.com/s/1smuDFtV 密码:xfnu 上传测试代码:/** * 测试图片上传 * @throws MyExcepti 阅读详情

相关推荐

Java实现上传文件图片到指定服务器目录

本文通过实例代码给大家介绍了java上传文件图片到指定服务器目录的相关知识,代码简单易懂,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

java上传图片

【代码】java上传图片

liujiahuan_的博客 9236

Win11系统下Abaqus2022与VS2022+oneAPI2023环境配置全攻略(附VUMAT子程序避坑指南)

本文详细指导在Windows 11系统下,为Abaqus 2022配置Visual Studio 2022与Intel oneAPI 2023的Fortran编译环境,以支持VUMAT等用户子程序开发。内容涵盖软件安装顺序、环境变量关联、快捷方式修改及关键验证步骤,并提供了首个VUMAT子程序的实战编写与模型验证方法,帮助用户高效搭建稳定可靠的仿真开发平台。

pytorch8learner的博客 319

java上传图片代码案例_java实现图片的上传与展示实例代码

java实现图片的上传与展示实例代码发布时间:2020-10-19 17:39:13来源:脚本之家阅读:86作者:MXC肖某某前言在很多的网站都可以实现上传头像,可以选择自己喜欢的图片做头像,从本地上传,下次登录时可以直接显示出已经上传的头像,那么这个是如何实现的呢?下面话不多说了,来一起看看详细的介绍吧一、注意事项:1,该项目主要采用的是springboot+thymeleaf框架2,代码展示的...

weixin_33883104的博客 1038

建议收藏:华为海思IC设计笔试题,含解析(附下载)

接触过的部门有麒麟芯片、CPU/GPU,总体面试感觉非常好,规范且认真,第一轮手撕代码状态机+复盘机考题+瞄准几个知识点深挖,时间1hour+;一二轮面试是连着的,所以很累。但是岗位就那么多,在面试的时候,很多同学因为准备不充分,与岗位失之交臂,无缘进入该公司。时序电路有记忆功能,不会产生锁存器,锁存器一般在组合逻辑中case写不全,else写不全,或者敏感列表写不全。

nuoweishizi的博客 3289

modbus-esp8266库深度解析:工业级Modbus协议栈实现

Modbus是一种广泛应用于工业自动化领域的通用串行通信协议,其核心在于标准化的功能码、寄存器模型与帧结构设计。基于RTU、ASCII和TCP三种传输变体,Modbus协议通过主从架构实现设备间可靠数据交互,具备低开销、高兼容性与强实时性等技术价值。在边缘计算与工业物联网场景中,它被广泛用于PLC通信、传感器数据采集、HMI集成及远程固件升级(FOTA)等关键任务。针对ESP8266/ESP32等Wi-Fi微控制器平台,modbus-esp8266库提供了完整协议栈支持,涵盖多实例并发、回调驱动架构、零拷贝

weixin_42315569的博客 351

java实现上传图片代码_Java图片上传实现代码

本文实例为大家分享了java图片上传代码,供大家参考,具体内容如下import java.io.*;import java.net.*;/**发送端*/class picsend{public static void main(String[] args) throws Exception{if(args.length!=1){System.out.println("请选择一张.jpg图片");r...

weixin_39901203的博客 1772

TC3XX - MCAL知识点(二十七):SENT Mcal配置及代码实战(单边半字节传输协议)

SENT协议只有一根线,异步传输!Sent协议的全称为Single Edge Nibble Trans .isson,单边半字节传输协议,是一种单线异步串行通信协议。Sent报文包含8个Nibble和一个校准位如图1所示,每一个Nibble数据被编码成PWM方式。设计这种协议的目的是用在与汽车ECU快速交互信息的传感器上,以此来取代低精确度的10bit AD和PWM。Sent是一种点对点的单方向从传感器到控制端的协议,控制器不需要同步信号。

梦想技术家 2272

Java实现图片上传源代码

Java实现图 1、文件上传 FORM 要加入enctype="multipart/form-data" ACTION或SERVLET import org.apache.commons.fileupload.DiskFileUpload; import org.apache.commons...

heima201907的博客 811

【AI智能体】Dify 搭建发票识别助手操作实战详解

Dify 搭建发票识别专属助手操作实战详解

congge 5549

Coze 上 OpenClaw 完整使用攻略(零代码 + 24 小时在线 + 飞书 / 微信接入)

Coze(扣子)是目前国内零门槛部署 OpenClaw 最友好的平台,无需服务器、不用命令行,5 分钟即可拥有可执行本地 / 云端任务的 AI 助手,还能一键发布到飞书、微信、钉钉等 IM。

hy行者勇哥的博客 2924

java图片上传代码_Java实现图片上传源代码

1、文件上传FORM要加入enctype="multipart/form-data"ACTION或SERVLETimport org.apache.commons.fileupload.DiskFileUpload;import org.apache.commons.fileupload.FileItem;基本方法如下:String temp=request.getSession().getSer...

weixin_34520503的博客 250

学Simulink——基于Simulink的PMSM矢量控制(FOC)从零搭建

《Simulink下PMSM矢量控制(FOC)全流程开发指南》 本教程系统讲解了基于Simulink的永磁同步电机(PMSM)磁场定向控制(FOC)实现方法。主要内容包括:FOC控制原理与双闭环架构设计、Simulink建模全流程(含PMSM本体建模、坐标变换、PI控制器设计等)、关键调试技巧以及工程扩展方向。教程以48V伺服电机为例,详细演示了从Clarke/Park变换到SVPWM生成的完整实现过程,并提供了参数配置建议和常见问题解决方案。通过本教程,读者可掌握FOC系统的核心实现技术,为开发高性能电机

xiaoheshang_123的博客 273

微信小程序之图片上传+java后台代码

微信小程序之图片上传+java后台代码 在小程序测试的时候一定要配置不校验安全域名,否则会报错 还是不说废话,直接演示 下面上代码: 1.wxml <view> <button bindtap='chooseImage'>选择图片</button> <view wx:if="{{imgs}}" wx:for="{{imgs}}" wx:key=...

蒋蒋 1801

Multisim14.0仿真应用设计(十六)74LS138译码器应用仿真

74LS138为3线-8线译码器。

zhusl6688的博客 2983

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

uniapp图片上传功能前后端代码(java)

重要点就 这两个,接受格式和后端的业务逻辑代码,(我这里是上传到阿里云OSS)上传的代码详细见(java上传文件至阿里云OSS)注意点:1.接口名 2.文件大小和类型限制 3.后端服务器要启动 4.如果前后端分离部署,确保后端支持跨域请求(CORS)//从相册选择album,从摄像机选择camera。//可以指定是原图还是压缩图,默认二者都有。//这里面是和图片一起传过来的数据。//默认为9,我们一次上传一张。//仅为示例,非真实的接口地址。"图片上传至本地成功""图片上传至本地失败"

2201_75559074的博客 1712

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

java图片上传代码_java 图片上传

代码是最有力量的,嘎嘎@CrossOrigin@ApiOperation(value = "上传图片", notes = "上传图片", httpMethod = "POST")@ApiImplicitParam(name = "file", value = "图片路径", required = true, dataType = "file")@ResponseBody@PostMapping("...

weixin_29696451的博客 1302

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

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

图片上传linux服务器保存、访问路径配置及JAVA代码开发

一、图片上传linux服务器保存、访问路径配置   我们开发图片上传功能功能时一般不考虑把图片上传到项目下的目录,否则在重新部署项目可能会因遗忘而导致图片的丢失,由此需要把图片上传放置到相应Linux目录下保存,同时为了前端可以访问,需在Tomcat中进行配置。      1、配置保存目录(ps:以下是我个人路径配置,对应后面的代码,大家可自行配置自身的路径) # cd /usr/java...

qq_32365919的博客 2万+

java图片上传程序代码_Java图片上传代码

package com.bj95ol.test;import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;imp...

weixin_29876887的博客 239

layui富文本图片上传 + Java后台代码(1秒接入)

layui富文本图片上传 + Java后台代码 废话不多说,直接上代码 前端JS layedit.set({ uploadImage: { url: 'http://192.168.5.27:446/fillupf' //接口url ,type: 'post' //默认post } }); 后台JAVA @ResponseBody @Request...

my_batis的博客 2866

uniapp微信小程序图片上传java后台(全代码)

这里的是java后台,是springboot工程。 application.yml配置: server: port: 1221 spring: #自定义图片访问路径 mvc: #注意/**/后面的/是不用的,但是如果我不加我下面的代码会不好看,你们cody的时候记得去掉!还有这串注释 static-path-pattern: /houseapp/upload/*...

Ambitiouss的博客 5595

上传图片的表单java代码_Java模拟表单post提交,可支持图片上传详解

/*** 模拟表单post** @param textMap 文本域* @param fileMap 文件**/public static String postForm(String urlStr, Map textMap, Map fileMap) throws IOException {String res = "";HttpURLConnection conn = null;InputSt...

weixin_30605469的博客 98

java图片上传程序代码_JAVA 关于图片上传的代码

package com;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.jsp.*;import com.jspsmart.upload.*;public class uploadfiles extends HttpServlet{public void doGet(H...

weixin_30967451的博客 273

Java图片上传代码

 001 package com.bj95ol.test; 002     003 import java.io.BufferedReader; 004 import java.io.File; 005 import jav

qypengs的专栏 871
上一篇: B/S和C/S区别
下一篇: 网站
fancylovejava
博客等级 码龄16年 1052粉丝 184原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值