当前位置:首页 » 文件管理 » 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>
.....

这样就可以啦

热点内容
手机无线存储器 发布:2025-09-14 14:18:24 浏览:975
将编程纳入 发布:2025-09-14 14:08:20 浏览:400
android进度条使用 发布:2025-09-14 14:01:06 浏览:852
怎么看服务器哪些端口没有被占用 发布:2025-09-14 14:01:06 浏览:228
星际方块服务器家园世界如何禁足 发布:2025-09-14 14:00:52 浏览:344
我的世界如何创建一个有模组的服务器 发布:2025-09-14 13:42:40 浏览:330
安防场景如何选择服务器 发布:2025-09-14 13:20:48 浏览:741
php数组获取键 发布:2025-09-14 13:20:47 浏览:857
苹果和安卓哪个适合跑滴滴 发布:2025-09-14 13:07:55 浏览:995
怎么访问wamp 发布:2025-09-14 12:26:55 浏览:822