首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

struts2资料上传,upload

2013-04-09 
struts2文件上传,upload在后台文件中:private File image ? //文件private String imageFileName ? //文

struts2文件上传,upload

在后台文件中:

private File image; ? //文件

private String imageFileName; ? //文件名称

public String upload(){

? ? String realPath=ServletActionContext.getServletContext().getRealPath("/imag");

? ? File file=new File(realPath);

? ??if(!file.exists()){

? ??file.mkdirs();

}

try {

? ??FileUtils.copyFile(image, new File(file,imageFileName)); ? //copy到imag文件中

} catch (IOException e) {

? ??// TODO Auto-generated catch block

? ??e.printStackTrace();

}

? ??return "success";

}

?

public File getImage() {

? ??return image;

}

public void setImage(File image) {

? ??this.image = image;

}

public String getImageFileName() {

? ??return imageFileName;

}

public void setImageFileName(String imageFileName) {

? ??this.imageFileName = imageFileName;

}

?

jsp页面中:

<form action="user/user_upload.action" method="post" enctype="multipart/form-data">?

? ??<input type="file" name="image" border="1"/> <input type="submit" value="上传"/>

?</form>

?

?

这样就可以实现简单的文件上传了!

热点排行