当前位置:首页 » 文件管理 » struts图片上传实例

struts图片上传实例

发布时间: 2023-05-25 20:08:44

㈠ 怎么用struts2实现多图片上传

新建Web Project,在WebRoot下新建upload文件夹
在WebRoot下新建upload.jsp,上传界面

编写上传成功、失败的提示界面。
在WebRoot下新建uploadError.jsp

在WebRoot下新建 uploadSuccess.jsp

编写Action类

配置struts.xml文件,重置fileUpload拦截器。

测试,测试完成之后在tomcat下面webapps目录下找到项目对应的文件夹下的upload下查看

㈡ struts上传多张图片怎么做,要求可以说上传中文的,而且图片可以重复上传不被覆盖

你指的是一次上传多张吗?我这有个自己写的例子:
//上传实体类
public class Upload {
private File photoes; //封装上传文件的属性
private String photoesFileName; //封装上传文件的名称属性
private String photoesContentType; //封装上传文件的类型属性
private String targetdir; //保存路径
private String targetfilename; //保存的文件名

public File getPhotoes() {
return photoes;
}
public void setPhotoes(File photoes) {
this.photoes = photoes;
}
public String getPhotoesFileName() {
return photoesFileName;
}
public void setPhotoesFileName(String photoesFileName) {
this.photoesFileName = photoesFileName;
}
public String getPhotoesContentType() {
return photoesContentType;
}
public void setPhotoesContentType(String photoesContentType) {
this.photoesContentType = photoesContentType;
}
public String getTargetdir() {
return targetdir;
}
public void setTargetdir(String targetdir) {
this.targetdir = targetdir;
}
public String getTargetfilename() {
return targetfilename;
}
public void setTargetfilename(String targetfilename) {
this.targetfilename = targetfilename;
}
}
这是上传图片的Action类中的部分代码
//获得服务器上保存上传文件的目录images的绝对路径
String realpath = ServletActionContext.getServletContext().getRealPath("/images");
//设置保存文件的目录
uld.setTargetdir(realpath);
//设置目标文件名
uld.setTargetfilename(generateFileName(uld.getPhotoesFileName()));
//把doc内容复制到target
FileUtils.File(uld.getPhotoes(), new File(uld.getTargetdir(),uld.getTargetfilename()));

㈢ struts2上传图片

可以直接在上传的时候就创建一个tomcat下的目录吧 图片都放里面

㈣ 在Struts2中如何上传图片并将刚刚上传的图片立即显示出来

//action的关键代码
import com.xt.gyz.facelook.service.FacesService;
public class ShowPic extends ActionSupport {

private InputStream is;
private Integer id;
private FacesService facesService;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public void setFacesService(FacesService facesService) {
this.facesService = facesService;
}

public InputStream getIs() {
return is;
}

public void setIs(InputStream is) {
this.is = is;
}

@Override
public String execute() throws Exception {
Faces face=facesService.findById(id);
is=new ByteArrayInputStream(face.getPic());
// FileOutputStream fos=new FileOutputStream(new File("E:/body.jpg"));
//顷返 System.out.println(fos);
// System.out.println("face:"+face.getPic().length);
//圆乎消 fos.write(face.getPic());
// fos.flush();
// fos.close();
return super.execute();
}
}
//不要忘记struts.xml配置
......
<action name="showPic" class="showPicAction">
<result type="stream">
<param name="inputName">is</param>
<param name="contectType">image/jpg</橘知param>
</result>
</action>
.....

这样就可以啦

热点内容
dns的服务器跟ip地址 发布:2025-05-05 23:37:21 浏览:963
linuxoraclesqlplus 发布:2025-05-05 23:13:23 浏览:583
android文件分类 发布:2025-05-05 23:07:44 浏览:125
c语言学习路线 发布:2025-05-05 23:05:27 浏览:130
本尼迪试剂如何配置 发布:2025-05-05 22:53:10 浏览:628
android关闭数据 发布:2025-05-05 22:44:15 浏览:395
python发邮件脚本 发布:2025-05-05 22:39:05 浏览:285
我的世界服务器怎么获取音乐 发布:2025-05-05 22:23:32 浏览:100
win7数据库 发布:2025-05-05 22:19:04 浏览:198
微信在哪里改支付的手势密码 发布:2025-05-05 22:14:15 浏览:820