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

strust1 下传文件要点

2012-07-03 
strust1 上传文件要点?1. private transient FormFile formFile??2.String license new String(Util.ge

strust1 上传文件要点

?

1. private transient FormFile formFile;?

?

2.String license = new String(Util.getFile(licenseManageForm.getFormFile()),UTF8_STRING);?

?

?

3. Util.getFile

/**

* @param file

* @return

*/

public static byte[] getFile(FormFile file){

if(null == file)

return new byte[0];

InputStream stream = null;

try{

stream = file.getInputStream();

? ?byte[] readBuffer = new byte[0];

? ?

? ? //read

? ? byte[] buffer = new byte[READ_LENGTH];

? ? int readNum = -1;

? ?while ((readNum = stream.read(buffer, 0, READ_LENGTH)) != -1) {

? ?readBuffer = uniteByteArrays(readBuffer, buffer, readNum);

? ?}

? ?return readBuffer;

? ?

}catch(IOException ex){

log.error("", ex);

return new byte[0];

}finally{

try{

if(null != stream)

stream.close();

}catch(IOException ex){

log.error("", ex);

}

}

}

?

4.

jsp

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>

<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

?

<html:form action="LicenseManage.do?method=readLicenseFile" onsubmit="return checkFile();"

method="post" enctype="multipart/form-data" target="hidden_frame">

<input type="file" name="formFile" contentEditable="false"/>

</html:form>

热点排行