ssh 文件上传

时间:2018-02-24 14:01:25
【文件属性】:

文件名称:ssh 文件上传

文件大小:17.79MB

文件格式:RAR

更新时间:2018-02-24 14:01:25

java 基础

简单的文件上传package com.iss.action; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import org.apache.struts2.ServletActionContext; import com.iss.dao.TbUserinfo; import com.iss.server.Manager; import com.opensymphony.xwork2.ActionSupport; public class UserinfoAction extends ActionSupport { TbUserinfo userinfo; File myphoto; String myphotoFileName; String myphotoContentType; String savePath; Manager manage; public Manager getManage() { return manage; } public void setManage(Manager manage) { this.manage = manage; } public String getSavePath() { return savePath; } public void setSavePath(String savePath) { this.savePath = savePath; } public File getMyphoto() { return myphoto; } public void setMyphoto(File myphoto) { this.myphoto = myphoto; } public String getMyphotoFileName() { return myphotoFileName; } public void setMyphotoFileName(String myphotoFileName) { this.myphotoFileName = myphotoFileName; } public String getMyphotoContentType() { return myphotoContentType; } public void setMyphotoContentType(String myphotoContentType) { this.myphotoContentType = myphotoContentType; } public TbUserinfo getUserinfo() { return userinfo; } public void setUserinfo(TbUserinfo userinfo) { this.userinfo = userinfo; } public String addUserinfo() throws Exception { int flag = 0; String str = ServletActionContext.getServletContext().getRealPath(savePath); System.out.println(str); userinfo.setPhoto(savePath + "/" + myphotoFileName); FileOutputStream fos = new FileOutputStream(str + "/" + myphotoFileName); FileInputStream fis = new FileInputStream(myphoto); byte[] data = new byte[1024]; while ((flag = fis.read(data)) != -1) { fos.write(data); } fis.close(); fos.close(); // Transaction t= HibernateSessionFactory.getSession().beginTransaction(); boolean temp = manage.saveUserinfo(userinfo); // t.commit(); if (temp) { return SUCCESS; } else { return ERROR; } } }


【文件预览】:
FileUploadDemo
----.project(2KB)
----.mystrutsdata(240B)
----.springBeans(474B)
----.mymetadata(315B)
----src()
--------struts.xml(541B)
--------com()
----WebRoot()
--------WEB-INF()
--------uploadphoto()
--------index.jsp(2KB)
--------success.jsp(1KB)
--------META-INF()
----.myhibernatedata(661B)
----.settings()
--------org.eclipse.wst.jsdt.ui.superType.container(49B)
--------org.eclipse.wst.common.project.facet.core.xml(163B)
--------org.eclipse.wst.jsdt.ui.superType.name(6B)
--------.jsdtscope(658B)
----.classpath(7KB)

网友评论