首页编程java编程java中upload什么意思 Java 中uploadify3.1判断是否选择了文件

java中upload什么意思 Java 中uploadify3.1判断是否选择了文件

编程之家2023-10-1199次浏览

大家好,今天小编来为大家解答java中upload什么意思这个问题,Java 中uploadify3.1判断是否选择了文件很多人还不知道,现在让我们一起来看看吧!

java中upload什么意思 Java 中uploadify3.1判断是否选择了文件

java如何将对象暂存到内存中

form表单提交文件,建议用smartupload上传,暂存在web服务器目录下,然后稍微一下下面的代码,ftp上传后,删除暂存文件,ok

import java.io.File;

import java.io.FileInputStream;

java中upload什么意思 Java 中uploadify3.1判断是否选择了文件

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

java中upload什么意思 Java 中uploadify3.1判断是否选择了文件

import java.io.OutputStream;

import java.util.StringTokenizer;

import org.apache.commons.net.ftp.FTP;

import org.apache.commons.net.ftp.FTPClient;

import org.apache.commons.net.ftp.FTPReply;

import org.apache.log4j.Logger;

/**

* Ftp服务类,对Apache的commons.net.ftp进行了包装<br>

*依赖库文件:commons-net-1.4.1.jar

*

*@version 1.0 2008-02-18

*@author huchao@jbsoft

*/

public class FtpService{

public FtpService(String serverAddr, String lsenport, String userName,

String pswd){

this.ftpServerAddress= serverAddr;

this.port= Integer.parseInt(lsenport);

this.user= userName;

this.password= pswd;

}

/**

* FTP服务器地址

*/

private String ftpServerAddress= null;

/**

* FTP服务端口

*/

private int port= 21;

/**

* FTP用户名

*/

private String user= null;

/**

* FTP密码

*/

private String password= null;

/**

* FTP数据传输超时时间

*/

private int timeout= 0;

/**

*异常:登录失败

*/

private final I2HFException EXCEPTION_LOGIN= new I2HFException("COR101",

"FTP服务器登录失败");

/**

*异常:文件传输失败

*/

private final I2HFException EXCEPTION_FILE_TRANSFER= new I2HFException(

"COR010","FTP文件传输失败");

/**

*异常:IO异常

*/

private final I2HFException EXCEPTION_GENERAL= new I2HFException("COR010",

"FTP IO异常");

private static final Logger logger= Logger.getLogger(FtpService.class);

/**

*初始化FTP连接,并进行用户登录

*

*@return FTPClient

*@throws I2HFException

*/

public FTPClient initConnection() throws I2HFException{

FTPClient ftp= new FTPClient();

try{

//连接到FTP

ftp.connect(ftpServerAddress, port);

int reply= ftp.getReplyCode();

if(!FTPReply.isPositiveCompletion(reply)){

ftp.disconnect();

throw new I2HFException("COR010","FTP服务器连接失败");

}

//登录

if(!ftp.login(user, password)){

throw EXCEPTION_LOGIN;

}

//传输模式使用passive

ftp.enterLocalPassiveMode();

//设置数据传输超时时间

ftp.setDataTimeout(timeout);

logger.info("FTP服务器["+ ftpServerAddress+":"+ port+"]登录成功");

} catch(I2HFException te){

logger.info(te.errorMessage, te);

throw te;

} catch(IOException ioe){

logger.info(ioe.getMessage(), ioe);

throw EXCEPTION_LOGIN;

}

return ftp;

}

/**

*设置传输方式

*

*@param ftp

*@param binaryFile

* true:二进制/false:ASCII

*@throws I2HFException

*/

public void setTransferMode(FTPClient ftp, boolean binaryFile)

throws I2HFException{

try{

if(binaryFile){

ftp.setFileType(FTP.BINARY_FILE_TYPE);

logger.info("FTP文件传输方式为:二进制");

} else{

ftp.setFileType(FTP.ASCII_FILE_TYPE);

logger.info("FTP文件传输方式为:ASCII");

}

} catch(IOException ex){

logger.info(ex.getMessage(), ex);

throw EXCEPTION_GENERAL;

}

}

/**

*在当前工作目录下建立多级目录结构

*

*@param ftp

*@param dir

*@throws I2HFException

*/

public void makeMultiDirectory(FTPClient ftp, String dir)

throws I2HFException{

try{

StringBuffer fullDirectory= new StringBuffer();

StringTokenizer toke= new StringTokenizer(dir,"/");

while(toke.hasMoreElements()){

String currentDirectory=(String) toke.nextElement();

fullDirectory.append(currentDirectory);

ftp.makeDirectory(fullDirectory.toString());

if(toke.hasMoreElements()){

fullDirectory.append('/');

}

}

} catch(IOException ex){

logger.info(ex.getMessage(), ex);

throw EXCEPTION_GENERAL;

}

}

/**

*更改服务器当前路径

*

*@param ftp

*@param dir

*@throws I2HFException

*/

public void changeWorkingDirectory(FTPClient ftp, String dir)

throws I2HFException{

try{

if(!ftp.changeWorkingDirectory(dir)){

throw new I2HFException("COR010","目录["+ dir+"]进入失败");

}

} catch(I2HFException tfe){

logger.info(tfe.errorMessage, tfe);

throw tfe;

} catch(IOException ioe){

logger.info(ioe.getMessage(), ioe);

throw EXCEPTION_GENERAL;

}

}

/**

*上传文件到FTP服务器

*

*@param ftp

*@param localFilePathName

*@param remoteFilePathName

*@throws I2HFException

*/

public void uploadFile(FTPClient ftp, String localFilePathName,

String remoteFilePathName) throws I2HFException{

InputStream input= null;

try{

input= new FileInputStream(localFilePathName);

boolean result= ftp.storeFile(remoteFilePathName, input);

if(!result){

//文件上传失败

throw EXCEPTION_FILE_TRANSFER;

}

logger.info("文件成功上传到FTP服务器");

} catch(I2HFException tfe){

logger.info(tfe.getMessage(), tfe);

throw tfe;

} catch(IOException ioe){

logger.info(ioe.getMessage(), ioe);

throw EXCEPTION_FILE_TRANSFER;

} finally{

try{

if(input!= null){

input.close();

}

} catch(IOException ex){

logger.info("FTP对象关闭异常", ex);

}

}

}

/**

*下载文件到本地

*

*@param ftp

*@param remoteFilePathName

*@param localFilePathName

*@throws I2HFException

*/

public void downloadFile(FTPClient ftp, String remoteFilePathName,

String localFilePathName) throws I2HFException{

boolean downloadResult= false;

OutputStream output= null;

try{

output= new FileOutputStream(localFilePathName);

downloadResult= ftp.retrieveFile(remoteFilePathName, output);

if(!downloadResult){

//如果是文件不存在将异常抛出

throw new I2HFException("COR011","文件不存在");

}

logger.info("文件成功从FTP服务器下载");

} catch(I2HFException tfe){

logger.error(tfe.getMessage(), tfe);

throw tfe;

} catch(IOException ex){

logger.error(ex.getMessage(), ex);

throw EXCEPTION_FILE_TRANSFER;

} finally{

try{

if(output!= null){

output.close();

}

if(!downloadResult){

new File(localFilePathName).delete();

}

} catch(IOException ex){

logger.error("FTP对象关闭异常", ex);

}

}

}

/**

* Method setFtpServerAddress.

*

*@param ftpServerAddress

* String

*/

public void setFtpServerAddress(String ftpServerAddress){

this.ftpServerAddress= ftpServerAddress;

}

/**

* Method setUser.

*

*@param user

* String

*/

public void setUser(String user){

this.user= user;

}

/**

* Method setPassword.

*

*@param password

* String

*/

public void setPassword(String password){

this.password= password;

}

/**

* Method setTimeout.

*

*@param timeout

* String

*/

public void setTimeout(String timeout){

try{

this.timeout= Integer.parseInt(timeout);

} catch(NumberFormatException ex){

//默认超时时间500毫秒

this.timeout= 500;

}

}

/**

* Method setPort.

*

*@param port

* String

*/

public void setPort(String port){

try{

this.port= Integer.parseInt(port);

} catch(NumberFormatException ex){

//默认端口21

this.port= 21;

}

}

}

=====================================

jsp上传部分

===================================

<form method="post" name="uploadform" id="uploadform" action="upload" ENCTYPE="multipart/form-data">

<input type="hidden" name="service" value="com.jbsoft.i2hf.corpor.services.CstBatchBizServices.exclUpload"/>

<table cellspacing="0" cellpadding="0">

<tr>

<td width="20%" align="right">上传本地文件:</td>

<td width="80%"><input class="" style="width:300px" type="file" width="300px" name="exclname" id="exclname"/></td>

</tr>

</table>

</form>

============================================

上传的servlet用的是smartupload

,部分代码可以参考一下:

==========================================

SmartUpload su= new SmartUpload();

su.setCharset("UTF-8");

su.initialize(getServletConfig(), request, response);

su.setMaxFileSize(10240000);

su.setTotalMaxFileSize(102400000);

su.setAllowedFilesList("xls");

su.upload();

===========================================

代码里面有一些客户的信息,不能全部给你哈

upload/logo.png什么意思

upload/ logo.png

上传/图标.可移植网络图形格式

PNG,图像文件存储格式,其目的是试图替代GIF和TIFF文件格式,同时增加一些GIF文件格式所不具备的特性。可移植网络图形格式(Portable Network Graphic Format,PNG)名称来源于非官方的“PNG's Not GIF”,是一种位图文件(bitmap file)存储格式,读成“ping”。PNG用来存储灰度图像时,灰度图像的深度可多到16位,存储彩色图像时,彩色图像的深度可多到48位,并且还可存储多到16位的α通道数据。PNG使用从LZ77派生的无损数据压缩算法,一般应用于JAVA程序中,或网页或S60程序中是因为它压缩比高,生成文件容量小

Java 中uploadify3.1判断是否选择了文件

可以间接的判断已选择文件的总数来判断是否选择了文件。

即用方法$("#uploadmediaSrcfile").data('uploadify').queueData.queueLength;

获取到uploadify组件中选择的文件总数,如果返回的值大于0,则表示选择了文件,

反之则没有选择文件。

其中:

1、uploadmediaSrcfile是类型为file的input标签的id值;

2、date('uploadify')中的uploadify为固定值;

3、此方法在版本为Uploadify v3.2.1中是测试通过的。

具体可以参考jquery.uploadify.js源文件中的第312行和319行的代码

(它自己也是通过这种方式获取选择文件总数的)。

关于java中upload什么意思到此分享完毕,希望能帮助到您。

java中 gt 什么意思(JAVA 中&lt;t&gt;是什么意思,)java开发有什么用 java软件开发到底是干什么的