栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

SSH框架之文件上传

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SSH框架之文件上传

一:明确目标:

        显示出图片(要在server中配置映射路径)

二、具体思路、代码以及运行结果:
1、思路:

           1、创建一个upload界面主要上传文件

           2、在主界面中要写好上传文件的操作

           3、在clzAction中写好准备上传和上传图片的方法

2、代码:

upload.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://jsp.veryedu.cn" prefix="z"%>	
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>	






书籍新增/修改


	


文件:

clzList.jsp:


			
				${b.cid }
				${b.cname }
				${b.cteacher }
				
				
				
					修改
					删除
				    上传图片
				    
				
			
			

clzAction:(在此类中要定好三个属性:分别是: 1、上传的文件 2、上传的文件名 3、上传的文件类别)

	private File img;
	private String imgFileName;
	private String imgContentType;
 
	public File getImg() {
		return img;
	}
 
	public void setImg(File img) {
		this.img = img;
	}
 
	public String getImgFileName() {
		return imgFileName;
	}
 
	public void setImgFileName(String imgFileName) {
		this.imgFileName = imgFileName;
	}
 
	public String getImgContentType() {
		return imgContentType;
	}
 
	public void setImgContentType(String imgContentType) {
		this.imgContentType = imgContentType;
	}
 
	public String preUpload() throws Exception {
		this.result = this.cd.list(clz, null).get(0);
		this.req.setAttribute("result", result);
		return "upload";
	}
 
	public String upload() throws Exception {
		String destDir = "E:/temp/2021/mvc/upload";
		String serverDir = "/uploadImages";
		FileUtils.copyFile(img, new File(destDir + "/" + imgFileName));
		clz.setPic(serverDir + "/" + imgFileName);
		this.cd.edit(clz);
		return TOLIST;
	}

struts-sy.xml文件:

			/clz_list
			/clzList.jsp
			/clzEdit.jsp
		    /upload.jsp
		

3、运行结果:  

在主界面点击图片上传:

跳转到upload.jsp: 

 选择文件:

  点击提交之后,主界面将会显示:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/334791.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号