SSH框架搭建电商系统之图片上传与显示

本文介绍了如何在SSH框架下搭建电商系统中的图片上传功能。首先,从Jsp页面中获取上传的图片信息,确保表单包含`enctype="multipart/form-data"`属性。接着,将图片上传至服务器特定文件夹(如image/products/),并保存其路径。最后,展示如何调用这些路径以在系统中显示上传的图片。
摘要由CSDN通过智能技术生成

1.从Jsp页面提取上传的图片信息upload,<s:from>里要加 enctype="multipart/form-data"属性,上传的图片name="upload" type="file"


2.图片上传到指定路径(其中我上传的是到服务器下文件夹,并保存路径为image/products/***)

	private String imageFileName;
	private String imageContentType="jpg";
	public String save() throws IOException{
		
		//上传封面图片到服务器
		Date currentTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
		String dateString = formatter.format(currentTime);
		imageFileName = dateString;
		String realpath = "G:\\WorkPlace\\shop\\WebRoot\\images\\products"; //可更换
		System.out.println("realpath:"+realpath);
		if(upload!=null){
			File savefile = new File(new File(realpath),imageFileName+"."+imageContentType);
			if(!savefile.getParentFile().exists())
				savefile.getParentFile()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值